I have a listMy RequirementI need a LINQ lambda query to Group to a list if a Condition meets else do not group.i.e On a condition I want it to be grouped
else it should not be groupedI have searched net - I get details on grouping on condition and I couldn't get and understand on how the remaining item should be included without grouping.Some info found on net was for grouping Conditionally - but with that those items not meeting conditions do not include in the resultant list.For ExampleList<signal> = [{1,"a"},{40,""),{9,"a"},{52,"b"),{2,"b"},{99,""),{88,"b"}]
The expected resultant list is to be grouped by a,b but "" should not be grouped
- ResultantList = Group[0] ==> [{1,"a"}
- {9,"a"}],
- Group[1] ==>[ {52,"b"),
- {2,"b"},
- {88,"b"}] ,
-
- Group[3] [ {40,""}]
- Group[4][ {99,""} ]
Please share your solution for this.What I have tried:- var resultantList = sigList
- .GroupBy(s => s.SignalGroup)
- .Select(grp => grp.ToList())
-
- .ToList();
With the above as expected
- Uncommenting Where clause groups only a and b==> All those items with empty value ( "" ) does not get included
- Commenting Where clause groups a,b and "" string to make a list with 3 groups(a,b and "").