C# exclusive enum -


this question has answer here:

i trying use enum represent different types order. there no compiler support ensure values mutually exclusive. example, have totally leagle enum

public enum mysearchtype{     searchbyname = 1,     searchbyid = 2,     searchbyordernumber = 2 //i meant have 3, overlooked.                              //so compiler give me error here. } 

is there anyway in c# achieve want do?

the standard thing when need order in c# enum order first value , let rest auto-increment

public enum mysearchtype{     searchbyname = 1,     searchbyid,          //implicitly 2     searchbyordernumber, //implicitly 3 } 

i believe (and wrong here) enum instances in c# implemented integer alias there no way ensure no duplicates (nor want to, makes perfect sense allow aliases same enum value).

perhaps want dictionary<int, string> or ienumerable<tuple<string, int>> .distinct() called on instead?


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -