TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

C# char.IsLower Methods

This C# example program demonstrates the char.IsLower method. IsLower tests for lowercase chars.

Char.IsLower. The char.IsLower method tests for lowercase letters.

It returns false on all characters except the lowercase "a" through "z". And char.IsUpper meanwhile returns true only on "A" through "Z".

Example. First, this example shows eight calls to the char.IsLower and char.IsUpper methods on the char type. It then shows the output of two if-statements with these calls. This is how the char.IsLower and char.IsUpper static methods are used.

Note: They return a Boolean, which you can use to test in an if-statement. If a char is not lowercase, they return false.

C# program that uses char.IsLower

using System;

class Program
{
    static void Main()
    {
	char c1 = 'a'; // Lowercase letter
	char c2 = 'b'; // Lowercase letter
	char c3 = 'C'; // Uppercase letter
	char c4 = '3'; // Digit

	if (char.IsLower(c1) || // True
	    char.IsLower(c2) || // True
	    char.IsLower(c3) || // False
	    char.IsLower(c4))   // False *
	{
	    Console.WriteLine("A char is lowercase.");
	}

	if (char.IsUpper(c1) || // False
	    char.IsUpper(c2) || // False
	    char.IsUpper(c3) || // True
	    char.IsUpper(c4))   // False *
	{
	    Console.WriteLine("A char is uppercase.");
	}
    }
}

Output

A char is lowercase.
A char is uppercase.

The first four lines declare four characters, two of which are lowercase letters. Next the char.IsLower tests are chained in an "or" conditional. The two if-statements the four example chars for lowercase or uppercase letters.

Note: In the first if, the first char is lower so only that test will be executed. In the second if, the third char is upper.

And: For non-letter chars such as digits and punctuation, IsLower and IsUpper will return false.

Change case. In the .NET Framework, you can also change the case of the characters by using the char.ToLower and char.ToLower method. Those methods actually perform the conversion, while IsLower and IsUpper just do the testing.

char.ToLower

Summary. We used the char.IsLower and char.ToUpper methods. These methods are actually contained in the System namespace. But because char is actually an alias for System.Char, you do not need to include it.

And: We saw how these methods will return false on input that is not a character such as a digit.


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf