Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

Writing into a file in C#

You can generate a file and write content to it easily by this code.

using --> It will automatically dispose/release the resources once the operation done.

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.IO;
  6.  
  7. namespace ConsoleApplication3
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. // Choose a path for saving a file
  14. string path = "D:\\tmp.txt";
  15.  
  16. // Enter value for writing into a file
  17. string input = Console.ReadLine().ToString();
  18.  
  19. using (StreamWriter streamWriter = new StreamWriter(path))
  20. {
  21. streamWriter.Write(input);
  22. }
  23. }
  24. }
  25. }


..