Try this:
var data =
File
.ReadAllLines(@"@"C:\..\..\..\..\..\..\..\ex1.txt"")
.Select(line => line.Split(','))
.Select(parts => new
{
city = parts[0],
temperature = decimal.Parse(parts[1].Trim())
})
.ToArray();
Array.ForEach(data, item => Console.WriteLine(item.city));
Console.WriteLine(data.Average(item => item.temperature));
I get this:
Londres
Berlin
New York
Tokyo
11.25
solved c# split and then make math operation [closed]