Using WriteAllLines method
using System.IO;
using System;
class WriteFile
{
    /* WriteAllLines creates a file, writes a collection of strings to the file, 
     and then closes the file. */
    static void Main()
    {
        string fileLoc = "D://MyFile.txt";
        // Create a string array that consists of three lines. 
        string[] lines = { "line 1", "line 2", "line 3" };
        File.WriteAllLines(fileLoc, lines);
        Console.WriteLine("Written to file successfully");
        Console.ReadLine();
    }
}Output:
Written to file successfully