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.