Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Fórum ➡ Calculate the Sum of Values in List of KeyValuePair<> objects ♦
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 #define DISPLAY_THE_TABLE_ROWS using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; // aljodav // http://rextester.com/users/376 // in reply to the MSDN thread // http://bit.ly/2fGT2w5 namespace Rextester { using Data=KeyValuePair<string,int>; class Program { static List<Data> GetList(){ return new List<Data>{ new Data("Jim",100), new Data("Jim",200), new Data("Mae",567), new Data("Ana",31), new Data("Ana",13), new Data("Mae",210), new Data("Jim",700), }; } public static void Main(string[] args) { GetList() .GroupBy(kvp=>kvp.Key,kvp=>kvp.Value,(key,values)=>new{ Name=key, Total=values.Sum() }) .ToList() .ForEach(x=>Console.WriteLine("\t\t{0}\t{1}",x.Name,x.Total)) ; Console.WriteLine("\n\nHello, world!"); } } }
run
|
edit
|
history
|
help
0
TotalHours FromTicks
asxs xscsss
project euler 14, C#
Chandramouli
Xml in C#
Binary Search Tree
4.3 Static typing: benefits, drawbacks and ways to minimise them
Dictionary that tells which key was not present
Ventmatika testas
2 3