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

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -