so i have my class, here:
MyClass
{
public MyClass(Sort sort, string name){ this.srt = sort; this.Name = name; }
public enum Sort { First, Second, Third, Fourth }
public Sort srt { get; set; }
public string Name { get; set; }
}
I have a list full of entries of MyClass, and I'm looking to sort them into groups by their srt
property, and then alphabetize those groups. for instance
List<MyClass> list = new List<MyClass>() {
new MyClass(MyClass.Sort.Third, "B"),
new MyClass(MyClass.Sort.First, "D"),
new MyClass(MyClass.Sort.First, "A"),
new MyClass(MyClass.Sort.Fourth, "C"),
new MyClass(MyClass.Sort.First, "AB"),
new MyClass(MyClass.Sort.Second, "Z")
};
then id like the output to be: (showing Name)
A
AB
D
Z
B
C
So to sum it up once again, i need to sort the list into sections by the enum, and then sort the sections by name. (NOTE: i just used this class as an example therefore, the enum isnt just going to be first, second etc, all the text values are names of things... but i do want to be able to choose the order of the sections.)
Ive played with using some foreach(var in list) to separate them into their sections, but this just seems slow and ineffective, as ill be doing this LOTS of times, with large lists.
Then i thought, maybe LINQ, or some compare method, but I'm not sure how that would be done!
Thanks for any responces!