In C#, what is the difference between ToUpper() and ToUpperInvariant()?
Can you give an example where the results might be different?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
ToUpperuses the current culture.ToUpperInvariantuses the invariant culture.The canonical example is Turkey, where the upper case of “i” isn’t “I”.
Sample code showing the difference:
For more on Turkish, see this Turkey Test blog post.
I wouldn’t be surprised to hear that there are various other capitalization issues around elided characters etc. This is just one example I know off the top of my head… partly because it bit me years ago in Java, where I was upper-casing a string and comparing it with “MAIL”. That didn’t work so well in Turkey…