0

Hello how to read from a file,which contains only nimbers(int) and to record them in an array.It's sounds easy,but i can't do it:(

for file example:
1234
4353
2345
2345
2312
1267

I mean they are in collom.
Thanks in advance.

3
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by Momerath
0

Try it this way:

string path = @"C:myFolder\myFile.txt";
            List<int> list = new List<int>();
            using (StreamReader sr = new StreamReader(path))
            {
                string line;
                while ((line = sr.ReadLine()) != null)
                    list.Add(Convert.ToInt32(line));
            }

            //generic list<T> now has all the numbers in the collection! 
            //generic list is better then a simple array (int[]).
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.