fork download
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.IO;
  5.  
  6. public class Test
  7. {
  8.  
  9. public static void Main()
  10. {
  11. var listDegree = new[] { 1, 4, 5, 6 };
  12.  
  13. var totalCosts = listDegree
  14. .Select((num,index) => new{num,index})
  15. .GroupBy(x => x.index / 2)
  16. .Select(g => g.Sum(x => x.num));
  17.  
  18. foreach(var totalCost in totalCosts)
  19. Console.WriteLine(totalCost);
  20. }
  21. }
Success #stdin #stdout 0.05s 34176KB
stdin
Standard input is empty
stdout
5
11