1
Answer

List (multidimentional) : How to get the sum of the 3rd column ?

Photo of chris combe

chris combe

2y
772
1
var lst = new List<(string country, string population, int number)> { };

lst.Add(("Germany", "83 Millionen", 16));
lst.Add(("USA", "328 Millionen", 40));
lst.Add(("Spain", "46 Millionen", 5));
C#

Hi,

How can I use "lst.Sum" to get the sum of the 3rd column (16 + 40 + 5) ? (What is the syntax) ?

int sum= lst.Sum( ?

Thanks!!

Answers (1)

3
Photo of Naimish Makwana
134 13.8k 203.9k 2y

Hello Chris,

Use below code.

int sum = lst.Sum(x => x.number);

Thanks

Naimish Makwana

Accepted