❔ Get collection of a groupBy based on key.
I have a list of KeyValuePairs <ushort, ushort>
I am attempting to group the list by the key,
csharp
What I am having trouble with is understanding the proper, efficient way to get all items of myNewCollection where the key is my playerId.
10 Replies
I could just do inside my player loop,
foreach (var item in list.Where(s => s.Key == player.Id))
However I believe that by first doing orderBy outside my player loop, I am limiting the overall amount of iterations
or at least that is my hope. Correct me if I am wrong.
ordering is going to be more inefficient than just applying a simple where filter.
I see.
So it is most practical then to just have the where filter inside my player loop?
There is perhaps no way to reduce the iterations more than that?
ToLookup
?you could convert that list to a lookup.
and accessing the list related to the player would be
lookup[player.Id]
👀
I've never heard of this before
Thank you!!
(I take that back - missed you were looping over players)
The idea is to do an initial iteration for sorting, before my player loop
ah, thank you. I think ToLookup is what I needed
Yep
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.