public bool EndsWith(string value)
string fileName = "example.txt"; if (fileName.EndsWith(".txt")) { Console.WriteLine("This is a text file."); }
string fileName = "example.docx"; if (fileName.EndsWith(".docx")) { Console.WriteLine("This is a Word document."); }
string fileName = "example.png"; if (fileName.EndsWith(".png") || fileName.EndsWith(".jpg")) { Console.WriteLine("This is an image file."); }Library: This method is included in the System.IO namespace of the .NET Framework.