I have an enum with a bunch of names / values. This is nice as I can
code using the names, instead of memorizing the values.
But, let's say something gives me a value. Now, while my code is happy
using a number, what if I want to display the name that this value
means?
Can I get the enum name, as it is typed in code, from the enum? or do
I need to write another array of strings to accomplish this?
Zytan 3 18595
Zytan <zy**********@yahoo.comwrote:
I have an enum with a bunch of names / values. This is nice as I can
code using the names, instead of memorizing the values.
But, let's say something gives me a value. Now, while my code is happy
using a number, what if I want to display the name that this value
means?
Can I get the enum name, as it is typed in code, from the enum? or do
I need to write another array of strings to accomplish this?
Call ToString() on it:
using System;
enum Poster
{
Zykan,
Jon
}
class Test
{
static void Main()
{
Poster p = Poster.Jon;
string name = p.ToString();
Console.WriteLine (name);
}
}
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Zytan wrote:
I have an enum with a bunch of names / values. This is nice as I can
code using the names, instead of memorizing the values.
But, let's say something gives me a value. Now, while my code is happy
using a number, what if I want to display the name that this value
means?
Can I get the enum name, as it is typed in code, from the enum? or do
I need to write another array of strings to accomplish this?
Zytan
Just use the ToString method.
--
Göran Andersson
_____ http://www.guffa.com
Jon and Goran, you guys answer everything. Thanks for your help, I
appreciate it. ToString, of course, I should have guessed.
Zytan This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: mcdonamw |
last post by:
This may sound like a stupid stupid question and I figure it would b
more "general" than pertaining to a specific Language.
I'm using vb.net and I have a bunch of Const values in my program.
can...
|
by: dof |
last post by:
I'm trying the following and having problems. I get errors on the array declaration lines. Something about an array must have at least one element. Thanks in advance. D
#include stuff
....
...
|
by: Rob Jackson |
last post by:
HiI've got a struct, known by file A.c, which contains a pointer to
struct B. Struct B is unknown by file A.c (it is declared in C.h), and
contains a typedef enum, which is declared in a file B.h,...
|
by: Mark |
last post by:
Assume you've declared an enum ....
public enum MyEnum { First, Second, Third }
Without knowing the values of the enum, is it possible to iterate through
all the possible values...
|
by: Michael C |
last post by:
If a class inherits from another class, say Form inherits from control, then
I can assign the Form to a variable of type Control without needing an
explicit conversion, eg
Form1 f = new Form1();...
|
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: Mark P |
last post by:
I'm working on a project where I have something like
enum Modes {mode_a, mode_b, ...};
Due to project spec changes, the number of Modes has increased several
times. There are a few places...
|
by: Rohit |
last post by:
Is there any way by which I can find number of elements in an enum
list?
Generally I use one last element at the end to find out total number
of elements. e.g.
typedef enum{
SUN,
MON,
TUE,...
|
by: puzzlecracker |
last post by:
What's the fastests way to find a number of values in enum.
I came up with this. but I think it's over kill.
enum Type
{
VAL1,
VAL2,
VAL3
}
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
|
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,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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,...
| |