I want to add all the data obtained from json.

This code is available:

foreach (var capture in json.captures) { Console.WriteLine($"{capture.Key}, {captures.Value.Data}"); } 

All data is displayed in the console.

 Пример: 1: 242 2: 532 3: 264 

How to put them all together? From 1 to 3. Or pre-add and display in one result.

242 + 532 + 264 = result.

  • one
    json.captures.Sum(v=>v.Value.Data) ? - tym32167
  • Thank you very much))))) The solution was so simple. But I study and get a lot of experience. - Den2908
  • I think you can add that back. I'll tick it off. - Den2908

1 answer 1

To summarize collection items, use LINQ, for example

 json.captures.Sum(v=>v.Value.Data)