double sum = 0;int count = 0;string[] lines = System.IO.File.ReadAllLines("D:\\file.txt" ) ;for (int ix = 0; ix < lines.Length; ix++){ string line = lines[ix]; if (string.IsNullOrEmpty(line)) continue; sum += double.Parse(line); count++;}double average = count > 0 ? sum / count : 0.0;Console.WriteLine(string.Format("average: {0:N2}", average));Console.ReadLine();