C# exclusive enum -
this question has answer here:
- how prevent duplicate values in enum? 3 answers
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
Post a Comment