C Sharp File IO

Started by
1 comment, last by Jeffsg605 12 years, 4 months ago
How do you read a text file of integers into an array? I'm have a map in text format for XNA. I'm new to C Sharp and All I can find is how to read in strings. Thanks in advance.
Advertisement

How do you read a text file of integers into an array? I'm have a map in text format for XNA. I'm new to C Sharp and All I can find is how to read in strings. Thanks in advance.


Assuming the file is newline separated ints and only ints:


List<int> ints = new List<int>(File.ReadAllLines(filename).Select(s => int.Parse(s)));


Otherwise you'll need to read in the text and then break it up into chunks and handle bad input (like not ints, or extra whitespace or...)
That's perfect, thanks a lot. I couldn't find that anywhere.

This topic is closed to new replies.

Advertisement