Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27333

VS 2010 Grouping by already defined groups

$
0
0
I have a Dictionary(Of String, Integer) like so (excuse the lack of a type declaration, all the VB code you see was translated from C#):
Code:

Dim baseStatRelation = New Dictionary(Of String, Integer)() From { _
        {"HP", 2}, _
        {"ATK", 4}, _
        {"DEF", 5}, _
        {"SPATK", 2}, _
        {"SPDEF", 8}, _
        {"SPEED", 4} _
}

I group the given dictionary as so:
Code:

Dim groupedBaseRelation = baseStatRelation.OrderByDescending(Function(i) i.Value).GroupBy(Function(i) i.Value).ToList()
The following output is as such:
Code:

1: [SPDEF, 8]
2: [DEF, 5]
3: [ATK, 4], [SPEED, 4]
4: [HP, 2], [SPATK, 2]

I have defined my groups and what is inside the groups.

Later on, let's say I have a 2nd Dictionary(Of String, Integer) like so:
Code:

Dim addStatRelation = New Dictionary(Of String, Integer)() From { _
        {"HP", 3}, _
        {"ATK", 4}, _
        {"DEF", 7}, _
        {"SPATK", 2}, _
        {"SPDEF", 8}, _
        {"SPEED", 6} _
}

I want to be able to do a GroupBy() on this 2nd dictionary, but make sure the Groups created are the same ones as before. The order of the groups can be different (and in some cases, should be), but the content of the groups (the Key portion) must be identical/grouped the same way.

Here's an example output of the 2nd group (as to how I'd like it):
Code:

1: [SPDEF, 8]
2: [DEF, 7]
3: [SPEED, 6], [ATK, 4]
4: [HP, 3], [SPATK, 2]


Does anybody have any ideas where the heck I start on this? I can attempt to offer a better explanation if this is not clear enough (and it may not be; I might do a followup post just for clarification).

Viewing all articles
Browse latest Browse all 27333

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>