C# program to get an extension of a given file

Syntax:

string DirectoryInfo.Extension

Program:

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

Leave a Comment

error: Alert: Content is protected!!