LINQ group one type of item
Posted
by Nelson
on Stack Overflow
See other posts from Stack Overflow
or by Nelson
Published on 2010-05-14T15:06:50Z
Indexed on
2010/05/14
15:14 UTC
Read the original article
Hit count: 253
I have a List that has various derived classes. I may have something like this:
List<BaseClass> list = new List<BaseClass>() {
new Class1(),
new Class2(1),
new Class3(),
new Class2(2),
new Class4()
};
I am trying to use LINQ to semi-sort the list so that the natural order is maintained EXCEPT for Class2. All Class2 instances should be grouped together at the place that the first Class2 occurs. Here is what the output should be like:
List<BaseClass> list = new List<BaseClass>() {
new Class1(),
new Class2(1),
new Class2(2),
new Class3(),
new Class4()
};
I can't for the life of me figure out how to do this...
© Stack Overflow or respective owner