473,618 Members | 3,005 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

enum.ToString()

The ToString() function, when applied to a variable that is an enumeration
type, results in a string that is the name of the enumerated value that was
defined in the source code. This is cool, but how does one override the
function to have some values return a different string?

For example, suppose I have an enum with value for the types of DVD media
like

public enum DVD_Media
{
DVD_ROM = 1,
DVD_R,
DVD_RW,
DVD_R_Plus,
DVD_RW_Plus,
DVD_RAM
}

but I want the values to print as "DVD-ROM", "DVD-R", "DVD-RW", "DVD+R",
"DVD+RW", and "DVD-RAM" -- the C# syntax does not seem to permit me a
mechanism to override the ToString() method on this specific enumeration.

-Ken
Nov 16 '05 #1
10 7117
Hi, Ken

you might consider creating a function, which returns resource string using
as argument enum value and use this function instead of ToString().
enum.ToString() could be used to identify resource strings.

HTH
Alex

"Ken Allen" <ke******@sympa tico.ca> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
The ToString() function, when applied to a variable that is an enumeration
type, results in a string that is the name of the enumerated value that was defined in the source code. This is cool, but how does one override the
function to have some values return a different string?

For example, suppose I have an enum with value for the types of DVD media
like

public enum DVD_Media
{
DVD_ROM = 1,
DVD_R,
DVD_RW,
DVD_R_Plus,
DVD_RW_Plus,
DVD_RAM
}

but I want the values to print as "DVD-ROM", "DVD-R", "DVD-RW", "DVD+R",
"DVD+RW", and "DVD-RAM" -- the C# syntax does not seem to permit me a
mechanism to override the ToString() method on this specific enumeration.

-Ken

Nov 16 '05 #2
Ken,

Try Enum.GetNames(t ypeof(A_CTS_Typ e))
=============== =====
RBisch - C# enthusiast
ryanbischoff@PL ZyahooNO_SPAM.c om
"Ken Allen" <ke******@sympa tico.ca> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
The ToString() function, when applied to a variable that is an enumeration
type, results in a string that is the name of the enumerated value that was defined in the source code. This is cool, but how does one override the
function to have some values return a different string?

For example, suppose I have an enum with value for the types of DVD media
like

public enum DVD_Media
{
DVD_ROM = 1,
DVD_R,
DVD_RW,
DVD_R_Plus,
DVD_RW_Plus,
DVD_RAM
}

but I want the values to print as "DVD-ROM", "DVD-R", "DVD-RW", "DVD+R",
"DVD+RW", and "DVD-RAM" -- the C# syntax does not seem to permit me a
mechanism to override the ToString() method on this specific enumeration.

-Ken

Nov 16 '05 #3
Alex and Ken,

I think that using a function is a bad idea. Not because it is the
wrong thing to do, but there are better solutions that fit into the model of
what .NET offers. Namely, you should use attributes to attribute the
elements in the enumeration. For something like this, I prefer the
Description attribute in the System.Componen tModel namespace. With it, you
can do this:

public enum MyEnum
{
[Description("My first value.")]
Value,
[Description("My second value.")]
Value2
}

Once you do this, you can use reflection on the enumeration to get the
fields (the values are really just static fields) and then get the
attributes, and subsequently the description.

The advantage to doing this is that the information about the
enumeration stays with the enumeration. Additionally, you can have one
routine which will give you the information, and that's it, you won't have
to change it when you want to change the description.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"AlexS" <sa***********@ SPAMsympaticoPL EASE.ca> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Hi, Ken

you might consider creating a function, which returns resource string using as argument enum value and use this function instead of ToString().
enum.ToString() could be used to identify resource strings.

HTH
Alex

"Ken Allen" <ke******@sympa tico.ca> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
The ToString() function, when applied to a variable that is an enumeration type, results in a string that is the name of the enumerated value that

was
defined in the source code. This is cool, but how does one override the
function to have some values return a different string?

For example, suppose I have an enum with value for the types of DVD media like

public enum DVD_Media
{
DVD_ROM = 1,
DVD_R,
DVD_RW,
DVD_R_Plus,
DVD_RW_Plus,
DVD_RAM
}

but I want the values to print as "DVD-ROM", "DVD-R", "DVD-RW", "DVD+R",
"DVD+RW", and "DVD-RAM" -- the C# syntax does not seem to permit me a
mechanism to override the ToString() method on this specific enumeration.
-Ken


Nov 16 '05 #4
This sounds good, but how do I (simply) "use reflection" to get the
description?

So I declare a variable as "MyEnum enumValue;" and later on I assign a
specific value to this variable. How do I display the descriptive string
rather than the name of the enumerated value?

On another note, am I correct in my assessment that there is no mechanism to
override the ToString() methods on built-ins, and especially value types?

Is there not a format string that will format the description and not the
name or value of the enumeration variable?

-Ken

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in
message news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Alex and Ken,

I think that using a function is a bad idea. Not because it is the
wrong thing to do, but there are better solutions that fit into the model of what .NET offers. Namely, you should use attributes to attribute the
elements in the enumeration. For something like this, I prefer the
Description attribute in the System.Componen tModel namespace. With it, you can do this:

public enum MyEnum
{
[Description("My first value.")]
Value,
[Description("My second value.")]
Value2
}

Once you do this, you can use reflection on the enumeration to get the
fields (the values are really just static fields) and then get the
attributes, and subsequently the description.

The advantage to doing this is that the information about the
enumeration stays with the enumeration. Additionally, you can have one
routine which will give you the information, and that's it, you won't have
to change it when you want to change the description.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"AlexS" <sa***********@ SPAMsympaticoPL EASE.ca> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Hi, Ken

you might consider creating a function, which returns resource string

using
as argument enum value and use this function instead of ToString().
enum.ToString() could be used to identify resource strings.

HTH
Alex

"Ken Allen" <ke******@sympa tico.ca> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
The ToString() function, when applied to a variable that is an enumeration type, results in a string that is the name of the enumerated value that
was
defined in the source code. This is cool, but how does one override
the function to have some values return a different string?

For example, suppose I have an enum with value for the types of DVD

media like

public enum DVD_Media
{
DVD_ROM = 1,
DVD_R,
DVD_RW,
DVD_R_Plus,
DVD_RW_Plus,
DVD_RAM
}

but I want the values to print as "DVD-ROM", "DVD-R", "DVD-RW", "DVD+R", "DVD+RW", and "DVD-RAM" -- the C# syntax does not seem to permit me a
mechanism to override the ToString() method on this specific enumeration.
-Ken



Nov 16 '05 #5
Nicholas,

attributes are Ok when you don't think about localization. I think Ken, when
doing UI stuff, must consider what to do when another enum, like days of
week has to be displayed in non-English language

So, please correct "bad idea". It's not worse than yours.

HTH
Alex

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in
message news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Alex and Ken,

I think that using a function is a bad idea. Not because it is the
wrong thing to do, but there are better solutions that fit into the model of what .NET offers. Namely, you should use attributes to attribute the
elements in the enumeration. For something like this, I prefer the
Description attribute in the System.Componen tModel namespace. With it, you can do this:

public enum MyEnum
{
[Description("My first value.")]
Value,
[Description("My second value.")]
Value2
}

Once you do this, you can use reflection on the enumeration to get the
fields (the values are really just static fields) and then get the
attributes, and subsequently the description.

The advantage to doing this is that the information about the
enumeration stays with the enumeration. Additionally, you can have one
routine which will give you the information, and that's it, you won't have
to change it when you want to change the description.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"AlexS" <sa***********@ SPAMsympaticoPL EASE.ca> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Hi, Ken

you might consider creating a function, which returns resource string

using
as argument enum value and use this function instead of ToString().
enum.ToString() could be used to identify resource strings.

HTH
Alex

"Ken Allen" <ke******@sympa tico.ca> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
The ToString() function, when applied to a variable that is an enumeration type, results in a string that is the name of the enumerated value that
was
defined in the source code. This is cool, but how does one override
the function to have some values return a different string?

For example, suppose I have an enum with value for the types of DVD

media like

public enum DVD_Media
{
DVD_ROM = 1,
DVD_R,
DVD_RW,
DVD_R_Plus,
DVD_RW_Plus,
DVD_RAM
}

but I want the values to print as "DVD-ROM", "DVD-R", "DVD-RW", "DVD+R", "DVD+RW", and "DVD-RAM" -- the C# syntax does not seem to permit me a
mechanism to override the ToString() method on this specific enumeration.
-Ken



Nov 16 '05 #6
OK, now we are treading into more unfamiliar waters here. I have not worked
with resources in .Net yet, although I have used them in the past with C++
4/5/6.

My understanding is that resources are supposed to be implemented in a
satellite assemebly, but my application does not need that yet, and this
seems more complicated that I need right now.

Have any samples on how to setup and access these resource strings as the
translation of an enumerated value?

-Ken

"AlexS" <sa***********@ SPAMsympaticoPL EASE.ca> wrote in message
news:uN******** ******@TK2MSFTN GP09.phx.gbl...
Nicholas,

attributes are Ok when you don't think about localization. I think Ken, when doing UI stuff, must consider what to do when another enum, like days of
week has to be displayed in non-English language

So, please correct "bad idea". It's not worse than yours.

HTH
Alex

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in message news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Alex and Ken,

I think that using a function is a bad idea. Not because it is the
wrong thing to do, but there are better solutions that fit into the model
of
what .NET offers. Namely, you should use attributes to attribute the
elements in the enumeration. For something like this, I prefer the
Description attribute in the System.Componen tModel namespace. With it,

you
can do this:

public enum MyEnum
{
[Description("My first value.")]
Value,
[Description("My second value.")]
Value2
}

Once you do this, you can use reflection on the enumeration to get the fields (the values are really just static fields) and then get the
attributes, and subsequently the description.

The advantage to doing this is that the information about the
enumeration stays with the enumeration. Additionally, you can have one
routine which will give you the information, and that's it, you won't have to change it when you want to change the description.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"AlexS" <sa***********@ SPAMsympaticoPL EASE.ca> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Hi, Ken

you might consider creating a function, which returns resource string

using
as argument enum value and use this function instead of ToString().
enum.ToString() could be used to identify resource strings.

HTH
Alex

"Ken Allen" <ke******@sympa tico.ca> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
> The ToString() function, when applied to a variable that is an

enumeration
> type, results in a string that is the name of the enumerated value

that was
> defined in the source code. This is cool, but how does one override the > function to have some values return a different string?
>
> For example, suppose I have an enum with value for the types of DVD

media
> like
>
> public enum DVD_Media
> {
> DVD_ROM = 1,
> DVD_R,
> DVD_RW,
> DVD_R_Plus,
> DVD_RW_Plus,
> DVD_RAM
> }
>
> but I want the values to print as "DVD-ROM", "DVD-R", "DVD-RW", "DVD+R", > "DVD+RW", and "DVD-RAM" -- the C# syntax does not seem to permit me a > mechanism to override the ToString() method on this specific

enumeration.
>
> -Ken
>
>



Nov 16 '05 #7
Ken,

See inline:

"Ken Allen" <ke******@sympa tico.ca> wrote in message
news:OQ******** ******@TK2MSFTN GP10.phx.gbl...
This sounds good, but how do I (simply) "use reflection" to get the
description?
Assuming that you are using the Description attribute, you can do this:

public static string GetEnumValueDes cription(object value)
{
// Get the type from the object.
Type pobjType = value.GetType() ;

// Get the member on the type that corresponds to the value passed in.
FieldInfo pobjFieldInfo = pobjType.GetFie ld(Enum.GetName (pobjType,
value));

// Now get the attribute on the field.
DescriptionAttr ibute pobjAttribute = (DescriptionAtt ribute)
(pobjFieldInfo. GetCustomAttrib utes(typeof(Des criptionAttribu te), false)[0]);

// Return the description.
return pobjAttribute.D escription;
}

You should probably provide some error checking, but I think you get the
point.

So I declare a variable as "MyEnum enumValue;" and later on I assign a
specific value to this variable. How do I display the descriptive string
rather than the name of the enumerated value?

On another note, am I correct in my assessment that there is no mechanism to override the ToString() methods on built-ins, and especially value types?

Is there not a format string that will format the description and not the
name or value of the enumeration variable?
No, there is not.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

-Ken

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in message news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Alex and Ken,

I think that using a function is a bad idea. Not because it is the
wrong thing to do, but there are better solutions that fit into the model
of
what .NET offers. Namely, you should use attributes to attribute the
elements in the enumeration. For something like this, I prefer the
Description attribute in the System.Componen tModel namespace. With it,

you
can do this:

public enum MyEnum
{
[Description("My first value.")]
Value,
[Description("My second value.")]
Value2
}

Once you do this, you can use reflection on the enumeration to get the fields (the values are really just static fields) and then get the
attributes, and subsequently the description.

The advantage to doing this is that the information about the
enumeration stays with the enumeration. Additionally, you can have one
routine which will give you the information, and that's it, you won't have to change it when you want to change the description.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"AlexS" <sa***********@ SPAMsympaticoPL EASE.ca> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Hi, Ken

you might consider creating a function, which returns resource string

using
as argument enum value and use this function instead of ToString().
enum.ToString() could be used to identify resource strings.

HTH
Alex

"Ken Allen" <ke******@sympa tico.ca> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
> The ToString() function, when applied to a variable that is an

enumeration
> type, results in a string that is the name of the enumerated value

that was
> defined in the source code. This is cool, but how does one override the > function to have some values return a different string?
>
> For example, suppose I have an enum with value for the types of DVD

media
> like
>
> public enum DVD_Media
> {
> DVD_ROM = 1,
> DVD_R,
> DVD_RW,
> DVD_R_Plus,
> DVD_RW_Plus,
> DVD_RAM
> }
>
> but I want the values to print as "DVD-ROM", "DVD-R", "DVD-RW", "DVD+R", > "DVD+RW", and "DVD-RAM" -- the C# syntax does not seem to permit me a > mechanism to override the ToString() method on this specific

enumeration.
>
> -Ken
>
>



Nov 16 '05 #8
Alex,

"Bad" is a subjective term.

When it comes to localization, the routine can EASILY be changed so that
it will include a resource identifier which can be used to fetch the
description from a resource, instead of embedding it in the attribute.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"AlexS" <sa***********@ SPAMsympaticoPL EASE.ca> wrote in message
news:uN******** ******@TK2MSFTN GP09.phx.gbl...
Nicholas,

attributes are Ok when you don't think about localization. I think Ken, when doing UI stuff, must consider what to do when another enum, like days of
week has to be displayed in non-English language

So, please correct "bad idea". It's not worse than yours.

HTH
Alex

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in message news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Alex and Ken,

I think that using a function is a bad idea. Not because it is the
wrong thing to do, but there are better solutions that fit into the model
of
what .NET offers. Namely, you should use attributes to attribute the
elements in the enumeration. For something like this, I prefer the
Description attribute in the System.Componen tModel namespace. With it,

you
can do this:

public enum MyEnum
{
[Description("My first value.")]
Value,
[Description("My second value.")]
Value2
}

Once you do this, you can use reflection on the enumeration to get the fields (the values are really just static fields) and then get the
attributes, and subsequently the description.

The advantage to doing this is that the information about the
enumeration stays with the enumeration. Additionally, you can have one
routine which will give you the information, and that's it, you won't have to change it when you want to change the description.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"AlexS" <sa***********@ SPAMsympaticoPL EASE.ca> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Hi, Ken

you might consider creating a function, which returns resource string

using
as argument enum value and use this function instead of ToString().
enum.ToString() could be used to identify resource strings.

HTH
Alex

"Ken Allen" <ke******@sympa tico.ca> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
> The ToString() function, when applied to a variable that is an

enumeration
> type, results in a string that is the name of the enumerated value

that was
> defined in the source code. This is cool, but how does one override the > function to have some values return a different string?
>
> For example, suppose I have an enum with value for the types of DVD

media
> like
>
> public enum DVD_Media
> {
> DVD_ROM = 1,
> DVD_R,
> DVD_RW,
> DVD_R_Plus,
> DVD_RW_Plus,
> DVD_RAM
> }
>
> but I want the values to print as "DVD-ROM", "DVD-R", "DVD-RW", "DVD+R", > "DVD+RW", and "DVD-RAM" -- the C# syntax does not seem to permit me a > mechanism to override the ToString() method on this specific

enumeration.
>
> -Ken
>
>



Nov 16 '05 #9
Nicholas,

I never use bad in sense of good. Maybe too inflexible :-)

But about your remark - combination of Description attribute and resources
is probably most flexible and convenient implementation, which should be
used to document and present in UI not just enums, but also other objects.
I find also another advantage in resources - when you need to change later
some description, you don't need to change code.
And Ken,

you can start from
http://msdn.microsoft.com/library/de...rcemanager.asp -
there are samples how to retrieve strings from resources and links to
further information how to create resources for assemblies.

HTH
Alex

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in
message news:O3******** ******@TK2MSFTN GP09.phx.gbl...
Alex,

"Bad" is a subjective term.

When it comes to localization, the routine can EASILY be changed so that it will include a resource identifier which can be used to fetch the
description from a resource, instead of embedding it in the attribute.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"AlexS" <sa***********@ SPAMsympaticoPL EASE.ca> wrote in message
news:uN******** ******@TK2MSFTN GP09.phx.gbl...
Nicholas,

attributes are Ok when you don't think about localization. I think Ken, when
doing UI stuff, must consider what to do when another enum, like days of
week has to be displayed in non-English language

So, please correct "bad idea". It's not worse than yours.

HTH
Alex

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote

in
message news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Alex and Ken,

I think that using a function is a bad idea. Not because it is the wrong thing to do, but there are better solutions that fit into the model
of
what .NET offers. Namely, you should use attributes to attribute the
elements in the enumeration. For something like this, I prefer the
Description attribute in the System.Componen tModel namespace. With it,
you
can do this:

public enum MyEnum
{
[Description("My first value.")]
Value,
[Description("My second value.")]
Value2
}

Once you do this, you can use reflection on the enumeration to get the fields (the values are really just static fields) and then get the
attributes, and subsequently the description.

The advantage to doing this is that the information about the
enumeration stays with the enumeration. Additionally, you can have
one routine which will give you the information, and that's it, you won't

have to change it when you want to change the description.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"AlexS" <sa***********@ SPAMsympaticoPL EASE.ca> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
> Hi, Ken
>
> you might consider creating a function, which returns resource string using
> as argument enum value and use this function instead of ToString().
> enum.ToString() could be used to identify resource strings.
>
> HTH
> Alex
>
> "Ken Allen" <ke******@sympa tico.ca> wrote in message
> news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
> > The ToString() function, when applied to a variable that is an
enumeration
> > type, results in a string that is the name of the enumerated value

that
> was
> > defined in the source code. This is cool, but how does one override the
> > function to have some values return a different string?
> >
> > For example, suppose I have an enum with value for the types of
DVD media
> > like
> >
> > public enum DVD_Media
> > {
> > DVD_ROM = 1,
> > DVD_R,
> > DVD_RW,
> > DVD_R_Plus,
> > DVD_RW_Plus,
> > DVD_RAM
> > }
> >
> > but I want the values to print as "DVD-ROM", "DVD-R", "DVD-RW",

"DVD+R",
> > "DVD+RW", and "DVD-RAM" -- the C# syntax does not seem to permit

me a > > mechanism to override the ToString() method on this specific
enumeration.
> >
> > -Ken
> >
> >
>
>



Nov 16 '05 #10

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

Similar topics

4
10258
by: avivgur | last post by:
Hi, Suppose I have an enum declared as: enum Color {Red, DarkRed, Blue, DarkBlue} Color c = Color.DarkBlue; And I want the command "Console.WriteLine(c);" to print out "Dark Blue" instead of "DarkBlue". In effect, I should probably change the ToString() method that the enum uses to implement space insertion between words. The question is, how do I do this?
8
6333
by: cadilhac | last post by:
Hi, I have the following code: public enum MyColors { Red, Green, Blue } MyColors c = (MyColors)Enum.Parse(typeof(MyColors), "abcd"); Why do I get c = "abcd" after this code instead of getting a ArgumentException ? MSDN says that this expetion is triggered when value is a name, but not
3
15084
by: giant food | last post by:
This seems like a long shot, but I wondered if there's a way to loop over the values in an Enum. For example, say I have an Enum as follows: Public Enum statusValues Ready Running Finished Error End Enum
2
3392
by: Dennis | last post by:
I have an enum as follows: Public Enum myData FirstData = 6 SecondData = 7 end enum Is there anyway that I can return the Enum names by their value, i.e., I want to input 6 into a function and return the name "FirstData"
6
2997
by: giannik | last post by:
I have an Enum Structure Public Enum MyEnum EnumVal1=0 EnumVal2=1 EnumVal2=2 end enum I save in an access database this enum value as an integer (0=EnumVal1,
7
9823
by: Harris | last post by:
Dear all, I have the following codes: ====== public enum Enum_Value { Value0 = 0, Value1 = 10,
8
1930
by: tony | last post by:
Hello! I have below a for loop and a switch in the for loop. I have also a enum called colBlowStep with some values. I have also an array called m_columnBlowStep with some strings. All items in the array m_columnBlowStep is string because I have used ToString on each enum item as you can see. I want to use enum in the case statment in the switch. I know I can use string but I rather want to use enum.
6
34922
by: Rico | last post by:
Hello, I'm looking for a way to reference the string name of an enumerator. I know in VB.net you can do "MyEnum.ToString" and get the name instead of the integer value. Is there a way I can do something similar with an Enum created in Access? Alright, here is some air code to explain what I mean Public Enum MyEnum
11
6387
by: =?Utf-8?B?dG9iaXdhbl9rZW5vYmk=?= | last post by:
The following code is in a custom deserializer: object value = (int) 1; string nameToParse = Enum.GetName(field.FieldType, value); value = Enum.Parse(field.FieldType, nameToParse); Currently we follow the path below: intValue --enum name --enum value
0
8212
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8153
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8653
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8304
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7126
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6101
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4065
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4150
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1459
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.