I have a nested dictionary which looks like this:
Dictionary<string, Dictionary<string, int>> users = new Dictionary<string, Dictionary<string, int>>();
The first string is the name of the user, the second is the contest he is taking part in and the int is his score. One user can take part in multiple contests.
My task is to find the user with the highest score by adding all the points he has. For now I used this code :
foreach (var user in users)
{
bestUsers.Add(user.Key, 0);
foreach (var contest in user.Value)
{
bestUsers[user.Key] += contest.Value;
}
}
I want to know how to do it by using anonymous function looking something like this :
KeyValuePair<string, int> bestUser = users.OrderBy(x => x.Value.Sum());