473,382 Members | 1,752 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,382 software developers and data experts.

Difference of Enum and Enum.ToString()

Hi,

Can anyone please tell me if there is a difference between the two options
described below:

public enum PingerID {All, A=240, B, C, D, E, F, G, H, J, K, L, M, N, P, R,
T, Unknown};

for (PingerID Pid = PingerID.All; Pid <= PingerID.T; Pid++)
if (PingerID.IsDefined(typeof(PingerID), (int)Pid))
{
//Option1
cboSelectPinger.Items.Add(Pid.ToString());
//Option 2
cboSelectPinger.Items.Add(Pid);
}
Thanks,
Leo
Nov 17 '05 #1
1 2202
Hi,

When you plot the enum entry actually you plot the number, if your enum is
of integers (default) what it will happen is

All = 0
A = 240
B = 241
C = 242 and so on,

If you plot ToString() it will return the definition as string
All = "All"
A ="A"
B = "B" and so on.

Cheers
--
Salvador Alvarez Patuel
Exony Ltd - London, UK
"Leif Eirik Olsen" wrote:
Hi,

Can anyone please tell me if there is a difference between the two options
described below:

public enum PingerID {All, A=240, B, C, D, E, F, G, H, J, K, L, M, N, P, R,
T, Unknown};

for (PingerID Pid = PingerID.All; Pid <= PingerID.T; Pid++)
if (PingerID.IsDefined(typeof(PingerID), (int)Pid))
{
//Option1
cboSelectPinger.Items.Add(Pid.ToString());
//Option 2
cboSelectPinger.Items.Add(Pid);
}
Thanks,
Leo

Nov 17 '05 #2

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

Similar topics

2
by: John Bentley | last post by:
Can someone give me an example where an enumeration format string of g would return a different result to that of f? ...
10
by: Ken Allen | last post by:
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...
4
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...
8
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...
3
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...
6
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
by: Harris | last post by:
Dear all, I have the following codes: ====== public enum Enum_Value { Value0 = 0, Value1 = 10,
8
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...
6
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...
1
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...
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
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
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,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.