Newbie question;
How do I cast a text file to an array, after the file is read using StreamReader?
I have read many threads, code etc but I really need my hand held here, I just dont get it (especially using windows forms)...this is part of an assignment.... I've been going around in circle's over this for the last week...and I'm a desperate now.
Your help would be appreciated.
this code works as it is, but I don't have an array (not an arraylist cause no manipulation required)
string fileName = "";
string name;
string[] array = new string[8999];//initialize array and size of (NOT USED)
//int Count = 0;//set count to 0 to interate through file line by line for linear search
OpenFileDialog OpenFile = new OpenFileDialog();//declare variable
OpenFile.ShowDialog(); //show dialog box of files
OpenFile.Filter = "Text files(*.txt)|*.txt|All files (*.*) | *.*"; //filter by these file
types
OpenFile.FilterIndex = 0;//show first file type?
fileName = OpenFile.FileName;//declare variable
if (OpenFile.ShowDialog() == DialogResult.OK)//if file found then display results to screen
{
foreach (string content in OpenFile.FileNames)
{
TextReader sr = new StreamReader(content);//read file using streamreader
while ((name = sr.ReadLine()) != null)//read textreader variable line by line
{
listBox1.Items.Add(name);
}
sr.Close();
}