-2

I want to create a 2nd list from 1st list to show the sum with descending order.

1st list :
     ID               Value
    1                  20
    2                  40
    3                  10

2nd List:
 ID               Value
1                  70
2                  50
3                  10
Med Amin
  • 95
  • 1
  • 6

1 Answers1

1
  var list1 = new [] { new { id = 1, Value = 20 },  new { id = 2, Value = 40 }, new { id = 3, Value = 10 } }.ToList();


        var list2 = list1.
                        Select(x => new { x.id, 
                                          Value = list1.Where(y => y.id >= x.id).Sum(z => z.Value) }).
                        OrderByDescending(x=>x.Value).ToList();
Cato
  • 3,652
  • 9
  • 12