Program that uses GetExtension [C#]

Posted by senthil | 8:14:00 PM | , | 0 comments »

The Path type includes also support for extensions. We can get an extension, with GetExtension, or even change an extension with ChangeExtension. The method names are obvious and easy-to-remember. GetExtension handles extensions of four letters. It also handles the case where a file name has more than one period in it. This next program briefly tests GetExtension. You can find further details and benchmarks.

using System;
using System.IO;

class Program
{
    static void Main()
    {
 // ... Path values.
 string value1 = @"C:\perls\word.txt";
 string value2 = @"C:\file.excel.dots.xlsx";

 // ... Get extensions.
 string ext1 = Path.GetExtension(value1);
 string ext2 = Path.GetExtension(value2);
 Console.WriteLine(ext1);
 Console.WriteLine(ext2);
    }
}
Output

.txt
.xlsx

0 comments

Related Posts Plugin for WordPress, Blogger...