![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C# program to get the extension of a file in C#
To handle file paths, the Path class is used in C#.
Set the file name in a string −
string myPath = "D:\
ew\quiz.txt";
Now, to get the extension, use the GetExtension() method −
Path.GetExtension(myPath)
Here is the complete code −
Example
using System; using System.IO; namespace Demo { class Program { static void Main(string[] args) { string myPath = "D:\
ew\quiz.txt"; Console.WriteLine(Path.GetExtension(myPath)); } } }
Output
.txt
Advertisements