Hello all hope all is well, Im new to c# and new to the site so bare with a noob :). any way I have an assignment and Im running in to a problem where I don't know how to have c# read a text file and turn the numbers into the text file in to an array. To top it all off I need it to pass the parameters in to a text file. using python as a example i need it to look like this:

def readFile (filename):
    data = []
    source = file (filename)
    for line in source:
        words = line.split ()
        for word in words:
            data.append (int (word))
    source.close ()
    return data

I think I know how and/or where I can find the infor to .split and append it. and this is my febel attemp to try and do it in C#:

namespace Reaingfiles

{
    class program{


        public static void checkit(string file)
        int data[];
    {
        StreamReader src = new StreamReader(src);
        while(!src.EndOfStream)
        {
            string line = src.ReadLine();
            Console.WriteLine(line);

        }

    }


    static void Main()
    {
        checkit("data.txt");

    }
  }

}

im using system, system.i0, and system.text. I tried to make the data array, then I got lost again. But please help, thank you. and if this was a bad question please help me fine tune it.

Alternatively, I could just create an array from a file and pass the array as an argument, but I would rather not do that. The array wouldn't be that big, given the size of the text files, or I could convert the contents of the text file into a string and pass that. Either way, I want to avoid it.

I've tried mucking around with this a way to create a StreamReader Object, but I haven't found a way to pass that an argument to a function. If there's a way to do that, great!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.