vb.net - How to transform a repeating list into a list with a count? -


i have list(of transaction) :

type | state   ---------------- boat | buy boat | buy boat | sell car  | sell car  | sell car  | sell plane| buy 

how can transform list(of transactionshortened) :

type | state | quantity   ----------------------- boat | buy   | 2 boat | sell  | 1 car  | sell  | 3 plane| buy|  | 1 

elegantly.

use linq , enumerable.groupby:

dim transactiongroups =         t in transactions         group t key = new {             .type = t.type,             .state = t.state         } group         select new {             .type = key.type,             .state = key.state,             .quantity = group.count()         }  each tgroup in transactiongroups     dim type = tgroup.type     dim state = tgroup.state     dim quantity = tgroup.quantity   next 

Comments