A list of data object in the below format
Col1  Col2  Col3
B     45    36    
B     12    69   
A     46    76    
C     89    09    
B     451   37   
D     435   46   
A     450   50   
D     98    43   
B     358   39
A     987   89
Need to get result set like following format ( 'A' occurred 3 times ,'B' occurred 4 times etc.)
Value  Count
A      3   
B      4  
C      1    
D      2
How to get result set like above using LINQ or lambda expressions?
You can achieve it by lambda expression like
var list = from x in dataObjects
           group x by x.Col1 into g
           select new { Value = g.Key, Count = g.Count() };
And By using Linq Extension method GroupBy as answered by @Asif
You can use GroupBy for that.
var groupedlist = list.GroupBy(c => c.Col1)
                      .Select((key, c) => new {Value = key, Count = c.Count()});
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With