473,326 Members | 2,102 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,326 software developers and data experts.

Enum members same value problems

Hi,

namespace EnumTest
{
class Class1
{
public enum num
{
one = 1,
uno = 1,
eins = 1
}

[STAThread]
static void Main(string[] args)
{
Console.WriteLine( num.eins );
Console.WriteLine( num.uno );
Console.WriteLine( num.one );
}
}
}

outputs:
uno
uno
uno

How can I get the following output:
eins
uno
one

Origin Problem: I have a large Enum list with some double
values in it and need access to its diffrent names.

Anybody know, how to do this?

thanks

David

Nov 16 '05 #1
6 3607
David <an*******@discussions.microsoft.com> wrote:
namespace EnumTest
{
class Class1
{
public enum num
{
one = 1,
uno = 1,
eins = 1
}

[STAThread]
static void Main(string[] args)
{
Console.WriteLine( num.eins );
Console.WriteLine( num.uno );
Console.WriteLine( num.one );
}
}
}

outputs:
uno
uno
uno

How can I get the following output:
eins
uno
one


You can't. They're the same value. It's like saying that you want
Console.WriteLine (1+1) to display a different result from
Console.WriteLine (2)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
David wrote:
Hi,

How can I obtain the name of a specific double existing
enum value, like

public enum num
{
one = 1,
uno = 1,
eins = 1
}
string text = Enum.GetName( typeof( num ), num.one );

gets:

"one"

instead of

"uno"

Any ideas?


There is a chance to get all enum names which values
are equal to "wanted" value:

Type enumType=typeof(enum);

foreach(string enumItemName in Enum.GetNames(enumType) ) {
if( (enum) Enum.Parse(enumType, enumItemName)==wantedEnumValue ) {
Console.WriteLine(enumItemName);
}
}

Cheers

Marcin
Nov 16 '05 #3
Hi David,

This code should resolve your problem:

foreach(string enumItemName in Enum.GetNames(typeof(num)) ) {
Console.WriteLine(enumItemName);
}

Cheers

Marcin
Hi,

namespace EnumTest
{
class Class1
{
public enum num
{
one = 1,
uno = 1,
eins = 1
}

[STAThread]
static void Main(string[] args)
{
Console.WriteLine( num.eins );
Console.WriteLine( num.uno );
Console.WriteLine( num.one );
}
}
}

outputs:
uno
uno
uno

How can I get the following output:
eins
uno
one

Origin Problem: I have a large Enum list with some double
values in it and need access to its diffrent names.

Anybody know, how to do this?

thanks

David

Nov 16 '05 #4
Hi,

How can I obtain the name of a specific double existing
enum value, like

public enum num
{
one = 1,
uno = 1,
eins = 1
}
string text = Enum.GetName( typeof( num ), num.one );

gets:

"one"

instead of

"uno"

Any ideas?

David

Nov 16 '05 #5
David <an*******@discussions.microsoft.com> wrote:
namespace EnumTest
{
class Class1
{
public enum num
{
one = 1,
uno = 1,
eins = 1
}

[STAThread]
static void Main(string[] args)
{
Console.WriteLine( num.eins );
Console.WriteLine( num.uno );
Console.WriteLine( num.one );
}
}
}

outputs:
uno
uno
uno

How can I get the following output:
eins
uno
one


You can't. They're the same value. It's like saying that you want
Console.WriteLine (1+1) to display a different result from
Console.WriteLine (2)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #6
David wrote:
Hi,

How can I obtain the name of a specific double existing
enum value, like

public enum num
{
one = 1,
uno = 1,
eins = 1
}
string text = Enum.GetName( typeof( num ), num.one );

gets:

"one"

instead of

"uno"

Any ideas?


There is a chance to get all enum names which values
are equal to "wanted" value:

Type enumType=typeof(enum);

foreach(string enumItemName in Enum.GetNames(enumType) ) {
if( (enum) Enum.Parse(enumType, enumItemName)==wantedEnumValue ) {
Console.WriteLine(enumItemName);
}
}

Cheers

Marcin
Nov 16 '05 #7

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

Similar topics

20
by: Glenn Venzke | last post by:
I'm writing a class with a method that will accept 1 of 3 items listed in an enum. Is it possible to pass the item name without the enum name in your calling statement? EXAMPLE: public enum...
9
by: AngleWyrm | last post by:
"The C++ Programming Language" by Bjarne Stroustrup, copyright 1997 by AT&T, section 4.8 (pp 77): "A value of integral type may be explicitly converted to an enumeration type. The result of such a...
12
by: Steven T. Hatton | last post by:
Any opinions or comments on the following? I don't say it below, but I came out on the side of using enumerations over static constants. /* I'm trying to figure out the pros and cons of using...
4
by: Chris | last post by:
I've lurked around long enough... Time to interract =) I'm trying to make sense of the following. I can't quite wrap my head around what this is actually doing: ------------- typedef enum {...
16
by: Simon | last post by:
Hi all, I think I've seen someone passing an emumeration in code before. Can anyone tell me if thats possible and why i would want to. Many thanks Kindest Regards
2
by: tzvika.visman | last post by:
I write a MC++ wrapper for our company internal SDK that wrote in C++ native code for writing application with this SDK over C# and other .NET languages and most of my SDK API function return a...
13
by: Don | last post by:
How do I get an Enum's type using only the Enum name? e.g. Dim enumType as System.Type Dim enumName as String = "MyEnum" enumType = ???(enumName)
34
by: Steven Nagy | last post by:
So I was needing some extra power from my enums and implemented the typesafe enum pattern. And it got me to thinking... why should I EVER use standard enums? There's now a nice little code...
6
by: bsma1 | last post by:
I building a web service that has an enum I want the consuming application to be able to use. I have the enum declared in the web service as: public enum myEnum { ONE = 1, TWO = 2, };
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.