Created
November 4, 2016 02:38
-
-
Save masaru-b-cl/d6eddbac5b572bf3b914d595c134eec9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Program | |
{ | |
static void Main() | |
{ | |
var source = new [] { | |
new { Category = "A", Amount = 1000m }, | |
new { Category = "B", Amount = 1000m }, | |
new { Category = "B", Amount = 1000m }, | |
new { Category = "C", Amount = 1000m }, | |
new { Category = "C", Amount = 1000m }, | |
new { Category = "C", Amount = 1000m }, | |
}; | |
var results = source | |
.GroupBy(x => x.Category) | |
.Select(g => new { Category = g.Key, Amount = g.Sum(x => x.Amount)}); | |
foreach (var x in results) | |
{ | |
Console.WriteLine("Category:{0}, Amount:{1}", x.Category, x.Amount); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment