C Sharp File IO
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.
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...)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement