c# - Can I sort list of Enum as I sort the list of string? -
if have list of enum example
public enum color { red, blue, yellow, green, black }
and have list list<color> testlist;
for example, in testlist, have red, yellow , black
can sort testlist , hence black, red , yellow use sort() list of string?
and if use switch statement, there performance consideration switch string or enum? 1 faster?
thanks
you can order them this:
public enum color { red, blue, yellow, green, black } enum.getvalues(typeof(color)) .oftype<color>() .orderby(x => x.tostring());
result:
note: purposely left out detail regarding performance issues.. there won't noticeable performance issues in switch
.. don't worry :)
Comments
Post a Comment