LINQ - Sort List of objects using OrderBy EnumValue, and Union result set?

Using Color as enum just to make things clearer class ClassyClass { public string Name {get; private set;} public Color Color {get; private set;} public ClassyClass(id, string name, Color color) { ... } } var orderedList = collectionOfClassyClasses . OrderBy(x => x. Color!

= Color. Red) // False comes before true . ThenBy(x => x.

Color) . ThenBy(x => x.Name) .ToList() If collectionOfClassyClasses was some sort of collection of ClassyClass objects, then orderedList would be ordered so that all those with Color set to Red would come first, ordered by name, and then all the others ordered by color and then name. At least I think it would... haven't tested it :p Let me know if it doesn't, hehe.

Using Color as enum just to make things clearer class ClassyClass { public string Name {get; private set;} public Color Color {get; private set;} public ClassyClass(id, string name, Color color) { ... } } var orderedList = collectionOfClassyClasses . OrderBy(x => x. Color!

= Color. Red) // False comes before true . ThenBy(x => x.

Color) . ThenBy(x => x.Name) .ToList(); If collectionOfClassyClasses was some sort of collection of ClassyClass objects, then orderedList would be ordered so that all those with Color set to Red would come first, ordered by name, and then all the others ordered by color and then name. At least I think it would... haven't tested it :p Let me know if it doesn't, hehe.

Thank's for your response. Your edit proved to be correct, in that false is evaluated b4 true...your solution works great, thanks a ton! – PortageMonkey Jul 15 '09 at 16:53 Great to hear it worked out :) I'll remove the edit and fix the code so that it is correct instead =) – Svish Jul 15 '09 at 21:25.

You could take the first list and do a list.AddRange() which takes an ienumerable.

If collectionOfClassyClasses was some sort of collection of ClassyClass objects, then orderedList would be ordered so that all those with Color set to Red would come first, ordered by name, and then all the others ordered by color and then name. At least I think it would... haven't tested it :p Let me know if it doesn't, hehe.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions