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:

enum sorting

note: purposely left out detail regarding performance issues.. there won't noticeable performance issues in switch.. don't worry :)


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -