Krimson
Krimson

Reputation: 7674

Enum with int represented as hex values

I have the following enum

public enum GridType
{
    Walkable = 0xFF000000,
    UnWalkable = 0xFF00000,
    Walked = 0xFF00000,
    Start = 0xFF00000,
    Destination = 0xFF00000
}

The int values represent argb color values. (I know they are the same values, Ill put in the real ones later)


However the compiler throws an error:

Cannot implicitly convert type 'uint' to 'int'. An explicit conversion exists (are you missing a cast?)

What can I do to fix this?

Upvotes: 2

Views: 2626

Answers (1)

Jim Mischel
Jim Mischel

Reputation: 134085

You can make your GridType use uint:

public enum GridType: uint
{
    Walkable = 0xFF000000,
    // etc
}

See http://msdn.microsoft.com/en-us/library/vstudio/sbbt4032(v=vs.100).aspx

I thought you could cast, but according to comments, that won't work.

Upvotes: 8

Related Questions