How to Get File Extension in C#/CSharp

To get file extension in C#, we make use of GetExtension() static method of Path class, which resides in System.IO namespace.  Example is given below.

using System;
using System.IO;

namespace Hello_World
{

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

            Console.WriteLine(extension);
        }
    }
}

  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •