How to sort a list of enums by the enum indexes in C#? -
i have enum
:
public enum group { administration = 1, lawyers, propertymanagement bookkeeping, secretariat }
i have list
of group
also: list<group>
. need simple way sort values of list enum index.
so, example, list:
{ group.bookkeeping, group.administration, group.secretariat, group.administration }
will become:
{ group.administration, group.administration, group.bookkeeping, group.secretariat }
(administration first, bookkeeping second, secretariat last, in definition of enum). looking simple way (maybe using linq
), without manually looping or so.
array.sort()
uses underlying type default compare elements:
list<group> groups = new list<group>() { group.bookkeeping, group.administration, group.secretariat, group.administration }; groups.sort();
Comments
Post a Comment