Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Fórum GroupBy ➡ Sum & Aggregate customers' names
//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 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; // aljodav // http://rextester.com/users/376 namespace Rextester { using D=Rextester.CusCatData; public class CusCatData{ public string Cus,Cat; public int S15,S16; } public class Program { public static void Main(string[] args) { List<D> datas= new List<D>{ new D{Cus="kim",Cat="T3",S15=2,S16=5}, new D{Cus="kay",Cat="T2",S15=7,S16=6}, new D{Cus="ann",Cat="T1",S15=3,S16=3}, new D{Cus="jim",Cat="T2",S15=5,S16=6}, new D{Cus="tim",Cat="T1",S15=0,S16=5}, new D{Cus="bel",Cat="T2",S15=3,S16=6}, }; datas .GroupBy(x=>x.Cat,(cat,xs)=>new{ Cat=cat, S15=xs.Sum(y=>y.S15), S16=xs.Sum(y=>y.S16), All=xs.Aggregate("",(a,y)=>(a==""?a:a+",")+y.Cus), }) .ToList() .ForEach(grp=>Console.WriteLine("{0,3} {1,3} {2,3} {3}",grp.Cat,grp.S15,grp.S16,grp.All)) ; } } }
run
|
edit
|
history
|
help
0
IsDivisibleV2
BST
Список Лекарств
Interface with same methods
C++ lesson
Sandeep Chandra Bose
Working nullable DateTime C#
any predicate test
eden
axasxasxasaxsd