Does anyone know how to read in data from a text file and initialize a variable to the string value that was read in from the file. E.g
text file data:
100
200
300
I want to read in each value and assign it to a variable in my code.
This is the code I have done so far just to ilistrate my problem.
The name assingment works fine because ReadLine() returns a string but the read is returning the wrong value.
text file data:
100
200
300
I want to read in each value and assign it to a variable in my code.
This is the code I have done so far just to ilistrate my problem.
Code:
int x;
int y;
open_dlg.Filter = "Text documents (.txt)|*.txt";
if (open_dlg.ShowDialog() == true)
{
string fileName = open_dlg.FileName;
FileInfo theSourceFile = new FileInfo(fileName);
StreamReader stream = theSourceFile.OpenText();
name = stream.ReadLine();
x = stream.Read();
}
Comment