File Class in C#

In this article we will discuss about what is File Class in C#.
  • 2855

We can get the metadata of a file and for this purpose we have File Class in C#. The File Class contains the static methods which means we have to call those methods through the name  of the class itself rather than making object of the Class. This Class resides in System.IO namespace. We have realize that the method of the File Class are better used to perform small operations on the File like whether the file exists or not.

The following program to show the example of File Class in C#:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.IO;


namespace absclass


    class Program


        static void Main(string[] args)


            if (File.Exists("D:\\Megha\\meesha.txt"))


                Console.WriteLine("The file exists");




                Console.WriteLine("The file does not exists");









In the above program we have seen that Exists method of the File Class has been directly call by using its name rather than making the object of the Class.

Further Readings
You may also want to read these related articles.

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

© 2020 DotNetHeaven. All rights reserved.