Reputation: 13610
I have this filetypeenum:
public enum FileType : int
{
jpeg = 0,
png = 1,
}
why does it say == cant be applied to int type and FileType
when i try to compare:
int type = 1;
if( type == FileType.jpeg)
??
Upvotes: 0
Views: 98
Reputation: 63522
Try casting it
if((FileType)type == FileType.jpeg)
or
if(type == (int)FileType.jpeg)
Upvotes: 5
Reputation: 169018
Because the conversion is not implicit. C# will not automatically convert between enum types and the enum base type because in many situations this can cause behavior not expected by the programmer.
Try this instead:
if ((FileType)type == FileType.jpeg)
Upvotes: 4