string[] lines = { "First line", "Second line", "Third line" }; // WriteAllLines creates a file, writes a collection of strings to the file, // and then closes the file. You do NOT need to call Flush() or Close(). System.IO.File.WriteAllLines(@"C:\Users\Public\TestFolder\WriteLines.txt", lines);
string text = "A class is the most powerful data type in C#. Like a structure, " + "a class defines the data and behavior of the data type. "; // WriteAllText creates a file, writes the specified string to the file, // and then closes the file. You do NOT need to call Flush() or Close(). System.IO.File.WriteAllText(@"C:\Users\Public\TestFolder\WriteText.txt", text);