Open text file, loop through contents and check against

后端 未结 5 2239
清酒与你
清酒与你 2020-12-21 17:24

So I have a generic number check that I am trying to implement:

    public static bool isNumberValid(string Number)
    {
    }

And I want to

5条回答
  •  青春惊慌失措
    2020-12-21 18:04

    You don't need to read the entire file into memory all at once. You can write:

    using (var writer = new StreamWriter(outputPath))
    {
        foreach (var line in File.ReadLines(filename)
        {
            foreach (var num in line.Split(','))
            {
                writer.Write(num + " ");
                writer.WriteLine(IsNumberValid(num));
            }
        }
    }
    

    The primary advantage here is a much smaller memory footprint, as it only loads a small part of the file at a time.

提交回复
热议问题