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 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
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
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
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
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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 {...
|
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
|
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...
|
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)
|
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...
|
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,
};
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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
| |