I have a task that requires setting the int variables in a C# method from a line in a text file, running through the program and then repeating but with variables from the second line of the text file.
Each line of the text file would look similar to this
3 5 10
2 7 15
I am new to C# and am learning fast but have hit a brick wall with this one. Any help of suggestions would be greatly appreciated.
To read from the file, you can use the StreamReader
class, or File.ReadAllLines()
.
Then you can use String.Split(new[] {' '})
to get an array of strings (each one containing the number as a string) from the line.
Converting to an integer is easy, just foreach
through and use the Convert
class to change each to type int
.
Keep in mind we're not here to write code for you, and there are quite a few answers to your question out there if you just break down what you're trying to do.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments