Saturday, April 20, 2019 04:28

UPPERCASE and lowercase

There are times when we need to convert the letters of a string to either uppercase or lowercase. Fortunately, C# offers us two methods for this: ToUpper() and ToLower().  As imagined, the first one will convert all letters of a string into capital letters, while the latter will do the opposite, by converting them to small ones.

The output of the above program will look like this:

Conversion to uppercase and lowercase in C#

One instance where these methods could be useful would be when taking input from them, such as passwords, and validating them:

In the first check, we will get a False result. This is because the difference in casing will make the two string to be considered as different. In the second, by converting it to lower case and comparing it to a lowercase string literal, the result will be True.



Tags: , , ,

Leave a Reply