there is

 d = System.IO.File.ReadAllLines (filename)
                 .Select (str => str.Split (new [] {'', '\ t'}))
                 .Select (str => str [0])
                 .Select (str => Convert.ToDouble (str.Replace ('.', ',')))
                 .ToArray ();

What to write instead of .Select(str => str[0]) so that I process all the elements of the array?

  • one
    Remove .Select(str => str[0]) and in the line above use SelectMany - Nikita
  • one
    Convert.ToDouble(str.Replace('.', ',')) . You must use IFormatProvider cInfo = new CultureInfo("en-US"); double.Parse(str, cInfo); IFormatProvider cInfo = new CultureInfo("en-US"); double.Parse(str, cInfo); - Andrei NOP
  • @Nikita please reply. - andreycha
  • 2
    @Andrey, invariant culture is much better than en-US. - Qwertiy

1 answer 1

You must use the SelectMany extension SelectMany instead of Select :

 d = System.IO.File.ReadAllLines(filename) .SelectMany(str => str.Split(new[] { ' ', '\t' })) .Select(str => Convert.ToDouble(str.Replace('.', ','))) .ToArray(); 

Learn more about the differences between Select and SelectMany .

  • And how now to ignore those values ​​that are not converted to double? - kovdryavlad
  • Use double.TryParse(...) instead of Convert.ToDouble(...) . - Nikita