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
sdfnmj,k, mnfdc
congtodien
Dokkan 2.0
Fórum ➡ Filling in a DataTable from a list of KVP's ♦
User Defined Exception (Inherited from built-in Exception class)
Easy prgm
linq sort
barcos
Lambda Expressions Are Cool 2
multiplicação