How can i check if the file extension is uppercase or lowercase?

c#

Solution

Unlike the other answers so far, I'd probably stick with `EndsWith` but switch to the overload that accepts a `StringComparison` parameter, e.g.:

address.EndsWith("GIF",StringComparison.OrdinalIgnoreCase)

You should generally avoid using `ToLower` or `ToUpper` just to be able to perform a comparison, because most string comparison facilities in the framework offer some form of option that allows you to perform the comparison whilst ignoring case.

Problem

I have this line in my code: ``` if (address.EndsWith("GIF") || (address.EndsWith("BMP") || address.EndsWith("JPEG") || address.EndsWith("TIFF") || address.EndsWith("RAW") || address.EndsWith("PNG"))) ``` And for example now the website address in the address variable is: www.test.jpg Then it will never get in the IF and jump out/continue. I want it to be in all the extensions uppercase and lowercase for example "GIF" and "gif" How can i do it ? ( sub question If i want to check for file extension doing EndsWith("gif" is enough or i have to add a dot before it like".gif" or like ".jpeg" ? )

Original source