C#: do enums cast themselves as strings or integers as appropriate in the context

Posted by Craig Johnston on Stack Overflow See other posts from Stack Overflow or by Craig Johnston
Published on 2010-05-06T07:59:03Z Indexed on 2010/05/06 8:08 UTC
Read the original article Hit count: 175

Filed under:
|
|

If I have the enum:

public enum VehicleType
{
    Car = 0,
    Boat = 1,
    Bike = 2,
    Spaceship = 3
}

and I then do:

int X = 10;
VehicleType vt = (VehicleType)2;
X = X + vt;
Console.WriteLine("I travel in a " + vt + " with " + X + " people.");

What should the output be in C#?

© Stack Overflow or respective owner

Related posts about c#

Related posts about enums