C# program to get an extension of a given file

C# program to get 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

Recent Posts

error: Alert: Content is protected!!