Skip to content

Instantly share code, notes, and snippets.

@bsmaat
Created September 15, 2017 10:15
Show Gist options
  • Save bsmaat/00f6b5ef1a65dde21503f7bd6237c183 to your computer and use it in GitHub Desktop.
Save bsmaat/00f6b5ef1a65dde21503f7bd6237c183 to your computer and use it in GitHub Desktop.
enum Alphabet
{
A,
B,
C,
D,
E,
F,
G
}
public class MyClass
{
public Alphabet Alpha
{
get;
set;
}
public MyClass(Alphabet alpha) {
Alpha = alpha;
}
}
public class Prorgam
{
public List<MyClass> ListToSort = new List<MyClass>();
public List<Alphabet> EnumsToSortBy = new List<Alphabet>() { Alphabet.A, Alphabet.C, Alphabet.E};
public static void Main(string[] args)
{
// Fill ListToSort..
ListToSort.Add(new Myclass(Alphabet.A));
ListToSort.Add(new Myclass(Alphabet.B));
ListToSort.Add(new Myclass(Alphabet.C));
ListToSort.Add(new Myclass(Alphabet.D));
ListToSort.Add(new Myclass(Alphabet.E));
ListToSort.Add(new Myclass(Alphabet.F));
ListToSort.Add(new Myclass(Alphabet.G));
ListToSort.SortingMethod(EnumsToSortBy);
// now ListToSort is in order, like this:
/*
ListToSort[0] is MyClass with Alpha = Alphabet.A
ListToSort[1] is MyClass with Alpha = Alphabet.C
ListToSort[2] is Myclass with Alpha = Alphabet.E
ListToSort[3...6] Is MyClass with Alpha = the rest of the enum values (not fussed about order right now)
*/
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment