Vb.net 如何将重复列表转换为具有计数的列表?

Vb.net 如何将重复列表转换为具有计数的列表?,vb.net,list,count,Vb.net,List,Count,我有一份(交易)清单: 如何将其转换为(交易缩短的)列表: 优雅地 使用LINQ和: 由于我的类型和状态是object,我不得不稍微改变一下这个解决方案,主要是:groupt By Key=String.Format(“{0}{1}”、t.type.Id.ToString()、t.statut.Id.ToString())改为Group和With{.type=Group.First().type.Id、.statut=Group.First.statut.Id、.quantite=Group.C

我有一份(交易)清单:

如何将其转换为(交易缩短的)列表:

优雅地

使用LINQ和:


由于我的类型和状态是object,我不得不稍微改变一下这个解决方案,主要是:
groupt By Key=String.Format(“{0}{1}”、t.type.Id.ToString()、t.statut.Id.ToString())改为Group
With{.type=Group.First().type.Id、.statut=Group.First.statut.Id、.quantite=Group.Count()
Type | State  
----------------
boat | buy
boat | buy
boat | sell
car  | sell
car  | sell
car  | sell
plane| buy
Type | State | Quantity  
-----------------------
boat | buy   | 2
boat | sell  | 1
car  | sell  | 3
plane| buy|  | 1
Dim transactionGroups =
        From t In transactions
        Group t By Key = New With {
            .Type = t.Type,
            .State = t.State
        } Into Group
        Select New With {
            .Type = Key.Type,
            .State = Key.State,
            .Quantity = Group.Count()
        }

For Each tGroup In transactionGroups
    Dim type = tGroup.Type
    Dim state = tGroup.State
    Dim quantity = tGroup.Quantity  
Next