Search code examples
c#textparameterseditusing

How to connect my c# programme to a text file and edit parameters


I created an application which has 2 labels and 1 textbox. The first label will show the total number of days since the year began, while the second shows the number of tests in the year. In the textbox shows the number of tests that I have not studied.

When the program opens, you have to click a button to load an .txt file to get these numbers, they are saved when you exit by clicking in another button. I Wanted to know how to load the file and to save the parameters.

I'm developing in C#, grateful, sorry for bad english.


Solution

  • To read text use File.ReadAllLines

    List<string> lines = File.ReadAllLines(path).ToList();
    

    To write text use File.WriteAllLines

    File.WriteAllLines(path, lines.ToArray());
    

    Or some variation on those methods to suit your needs.