What is missing? C#
-
I am trying to read one text file, and create an Array.. Dos someone knews what am I doing wrong?? Can someone correct my code a little bit? private void panel13_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { ArrayList nodes = new ArrayList(); FileStream file = new FileStream("C:\\NeckingRa\\Temp\\cut.dat", FileMode.Open,FileAccess.Read); StreamReader sr = File.OpenText("C:\\NeckingRa\\Temp\\cut.dat"); String line; while ((line=sr.ReadLine())!=null) { string s = sr.ReadToEnd(); string[] values = line.Split(' '); } sr.Close(); file.Close(); }
-
I am trying to read one text file, and create an Array.. Dos someone knews what am I doing wrong?? Can someone correct my code a little bit? private void panel13_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { ArrayList nodes = new ArrayList(); FileStream file = new FileStream("C:\\NeckingRa\\Temp\\cut.dat", FileMode.Open,FileAccess.Read); StreamReader sr = File.OpenText("C:\\NeckingRa\\Temp\\cut.dat"); String line; while ((line=sr.ReadLine())!=null) { string s = sr.ReadToEnd(); string[] values = line.Split(' '); } sr.Close(); file.Close(); }
I would make the code look like this:
private void panel13_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
ArrayList nodes = new ArrayList();
StreamReader sr = File.OpenText("C:\\NeckingRa\\Temp\\cut.dat");
String line;
while ((line=sr.ReadLine())!=null)
{
string[] values = line.Split(' ');
nodes.AddRange(values);
}
sr.Close();
}The file variable is not needed and inside of the while look you were reading to the end of the file. Also you had never added the data in values to the nodes variable. I also like using @"c:\NeckingRa\Temp\cut.dat" in C# instead of the normal \\ that we all had to use in C++. Steve Maier, MCSD MCAD