473,394 Members | 1,770 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Enums

Is there a method which will return the "text" value of an enum? Say I have
and enum which looks like the following....
public enum DBSource
{
Speed_DB=0,
Clarify_DB=1,
PSI_DB=2,
RNASand_DB=3,
PRGOPS_DB=4,
PRGAdmin_DB=5,
MKIS_DB=6,
DataBarn_DB=7
}

In this particular situation, I have a text value of "MKIS" and I need to
know if that value is represented by one of the "enums" and then if it is, I
need to pass the Enum as a parameter of a method... something like
DBSource.MKIS. Is there a way for me to do this?

Thanks in advance for your assistance!

Nov 19 '05 #1
3 1099
aDBSource.ToString(); should return the text value.

Eliyahu

"Jim Heavey" <Ji*******@discussions.microsoft.com> wrote in message
news:DF**********************************@microsof t.com...
Is there a method which will return the "text" value of an enum? Say I have and enum which looks like the following....
public enum DBSource
{
Speed_DB=0,
Clarify_DB=1,
PSI_DB=2,
RNASand_DB=3,
PRGOPS_DB=4,
PRGAdmin_DB=5,
MKIS_DB=6,
DataBarn_DB=7
}

In this particular situation, I have a text value of "MKIS" and I need to
know if that value is represented by one of the "enums" and then if it is, I need to pass the Enum as a parameter of a method... something like
DBSource.MKIS. Is there a way for me to do this?

Thanks in advance for your assistance!

Nov 19 '05 #2
Jim Heavey wrote:
Is there a method which will return the "text" value of an enum?


Jim, check out this article:

Understanding Enumerations
http://aspnet.4guysfromrolla.com/articles/042804-1.aspx

In essence you can use the System.Enum.GetNames(type) to return the
string values of a given enumeration in a string array.

hth

--

Scott Mitchell [ASP.NET MVP]
mi******@4GuysFromRolla.com
http://www.4GuysFromRolla.com/ScottMitchell
Nov 19 '05 #3
Hey Scott, I enjoyed the article, but I am having difficulty in getting the
following instruction to work....

string[] names = System.Enum.Parse(GetType(Team.Common.RunMode.DBSo urce));

I get a compile error of "Team.Common.RunMode.DBSource' denotes a 'class'
where a 'variable' was expected).

I am attempting to reference the Enum called "DBSource" which is in a static
Class of Team.Common.RunMode. It looks equivalent to the instruction which I
found in the example you pointed me to. What am I doing wrong?

Thanks in advance for your assistance!

Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: SpaceCowboy | last post by:
I recently got into a discussion with a co-worker about using enums across a dll interface. He wanted to use chars instead, argueing that depending on compiler settings the size of an enum could...
2
by: Faisal | last post by:
Can anyone tell me if it is possible to enumerate through all the Enums within a class . I have a class with many Enums and would like to accees the Enums through an array/collection etc. I can't...
27
by: Mark A. Gibbs | last post by:
i have been toying with the idea of making my enums smarter - ie, more in line with the rest of the language. i haven't tested it yet, but what i came up with is a template like this: template...
2
by: SpotNet | last post by:
Hello CSharpies, Can Enums in C# be UInt32 Types, and not just Int32 Types. I have a lot of constant declarations that are UInt32 that I want to put in Enums to ease the use of Intellisence. I...
4
by: Martin Pritchard | last post by:
Hi, I'm working on a project that historically contains around 40 enums. In the database various fields refer to the int values of these enums, but of course ref integrity is not enofrced and...
2
by: Faisal | last post by:
Can anyone tell me if it is possible to enumerate through all the Enums within a class . I have a class with many Enums and would like to accees the Enums through an array/collection etc. I can't...
2
by: Simon Elliott | last post by:
I have some legacy C++ code which requires some enums to be 1 or 2 bytes in size. I'd ideally like to be able to specify that a few carefully selected enums are a particular size. By default,...
11
by: Marc Gravell | last post by:
This one stumped me while refactoring some code to use generics... Suppose I declare an enum MyEnum {...} Is there a good reason why MyEnum doesn't implement IEquatable<MyEnum> ? Of course,...
4
by: Jon Slaughter | last post by:
is there a simple way to "step" through enums? I have a button that I want to click and have it "cycle" through a set of states defined by enums but the only way I can think of doing this...
13
by: Bob | last post by:
Hi, Can someone explain why you can't declare enums in an interface? The compiler says "interfaces can't declare types" Ignoring the syntax implications it seems to me that you should be able to...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.