How to Create Text File in C#/CSharp

To create a text file in C#/CSharp, we make use of File class which contains Create static function.  This function will take text file path as parameter where you want to create the text file.

using System;
using System.IO;
namespace Hello_World
{

    class Program
    {
        static void Main(string[] args)
        {
            string file = @"C:\Users\ADMIN\Desktop\file.txt";

            File.Create(file);

            Console.WriteLine("File is created!");
        }               
    }
}

 

  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •