Difference of Enum and Enum.ToString()

L

Leif Eirik Olsen

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
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top