Writing Text Files

from Arrays

This creates a file asynchronously and write

public static async Task Method_WriteTextToFile() 
   string[] myText = { "Monday", "Tuesday", "Wednesday" };

   await System.IO.File.WriteAllLinesAsync("C:\temp\myTextFile.txt", myText);

from Collections

Available in .NET 4.0

System.Collections.Generic.List<string> myList; 
System.IO.File.WriteAllLines("C:\temp\SavedLists.txt", myList);

Prioir to .NET 4.0 you needed to use a StreamWriter

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext