I have a list of objects that contains different primitive data types:
List<object> list = new List<object>() {
3, "cat", 4.1, 'a', 5, "dog", "horse", 9.1, 'd', 1
};
I want to be able to run a Linq query on the above list that groups all the element by data type and order as (string, integer,double,character) (if that makes sense?). Something like:
list = { "cat","dog", "horse", 3, 5, 1, 4.1, 9.1, 'a', 'd' }
I tried from
Using Linq to group a list of objects into a new grouped list of list of objects
code
lst
.GroupBy(x => x.GetType())
.Select(grp => grp.ToList())
.ToList()
.ForEach(group => group.ForEach(item => Console.WriteLine(item)));
works but does not give the desired output.
output
{ 3, 5, 1, "cat","dog", "horse",4.1, 9.1, 'a', 'd' }