Beginner here, I'm having some troubles reading and writing to an existing .txt file. My overall goal is to receive strings containing equations (specified by numbers and +,-,*,/,(,) operators), running these equations through a calculator I built (see the Calculate method), and then writing the results to the same file. Say my file contains the following lines:
1+8
sin(90)+9
Then, I should write to that file, so it would look like this:
1+8 = 9
sin(90)+9 = 10
And so on.
Here's what I've got so far:
List<string> lines = new List<string>();
List<string> results = new List<string>();
foreach (string line in File.ReadLines(@"C:\Users\...\file.txt"))
{
string result = Calculate(line).ToString();
}
Now I'm really not sure what to do. I've been trying using File.WriteAllLines and File.AppendText, but an error is thrown, and the current stream seems to be occupied.
Any suggestions? Thanks.