C# Program to Get Extension of a Given File

You are currently viewing C# Program to Get Extension of a Given File

C# program to get extension of a given file

using System;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main()
        {
            DirectoryInfo d = new DirectoryInfo("sample.txt");

            Console.WriteLine("File extension is : " + d.Extension);
        }
    }
}

Output

File extension is : .txt

Ranjith Kumar

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply