Path.GetExtension method in c#

In this article I will explain Path.GetExtension method in C#.
  • 5852


C# path is a name of a directory which identify a unique location of a file in a file system. A path of a file system is expressed in a string of character.
Files have a specific extension. Path.GetExtension method Returns the extension of the specified path string. You can use Path.GetExtension 
method to test extensions in C#. Path.GetExtension method includes the separator character ".". Path.GetExtension checks the entire path for invalid chars.


using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.IO;

 class Program


    static void Main()


        string p = @"C:\Users\rahul\Documents\Test.txt";

        string e = Path.GetExtension(p);

        Console.WriteLine("Hi extention is:{0}",e);





The output of following program



© 2020 DotNetHeaven. All rights reserved.