Coffeehouse Post

Single Post Permalink

View Thread: Reading int from file in C#
  • User profile image
    Sven Groot

    No, there is no such thing. The closest you can get is this:

    foreach( string line = File.ReadLines(fileName) )
        foreach( string value in line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            someInt = Convert.ToInt32(value);

    Which could be very memory-intensive if the file contains very long lines.

    There may be third party libraries that are better at this, but I wouldn't know any off-hand.