How to sort a collection based on type in LINQ
问题 I have a collection like this, Class Base{} Class A : Base {} Class B : Base {} List<Base> collection = new List<Base>(); collection.Add(new A()); collection.Add(new B()); collection.Add(new A()); collection.Add(new A()); collection.Add(new B()); Now I want to sort the collection based on type (A/B). How I can do this? Please help me. 回答1: You can use the type information itself: collection.Sort( (a,b) => { bool aType = a.GetType() == typeof(A); bool bType = b.GetType() == typeof(A); return