user979331 user979331 - 3 months ago 22
C# Question

Public enum with int values

I have defined a public enum like so:

public enum guests
{
One,
Two
}


What I am trying to do is to have it like the following

public enum guests
{
1,
2
}


but I keep getting this error when I try that:

Identifier expected


Can I set int instead of strings?

Answer

You probably want this:

public enum guests
{
    One = 1,
    Two = 2
}
Comments