TheDeveloperBlog.com

Home | Contact Us

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

C# ToUpper Method

This C# example program uses the ToUpper method. It demonstrates the output of ToUpper.

ToUpper uppercases all letters in a string.

It is useful for processing text input or for when you need to check the string against an already uppercase string. It has no effect on non-lowercase characters.

Example. ToUpper is an instance method on the string type, which means you must have a string variable instance to call it. ToUpper works the same as ToLower except it changes lowercase characters to uppercase characters.

ToLower

C# program that uses ToUpper

using System;
using System.Globalization;

class Program
{
    static void Main()
    {
	//
	// Uppercase this mixed case string.
	//
	string value1 = "Lowercase string.";
	string upper1 = value1.ToUpper();
	Console.WriteLine(upper1);

	//
	// Uppercase this string.
	//
	string value2 = "R2D2";
	string upper2 = value2.ToUpper(CultureInfo.InvariantCulture);
	Console.WriteLine(upper2);
    }
}

Output
    (Second string is not changed.)

LOWERCASE STRING.
R2D2

ToUpper converts all lowercase characters to uppercase characters, ignoring non-lowercase characters such as the uppercase L and the period. The second part tries to uppercase a string that is already uppercased. Nothing is changed.

Next, the CultureInfo.Invariant culture class specifies that you want the string to be uppercased the same way on all computers that might run your program. It is useful for larger programs.

Tip: If you need to uppercase the first letter, consider ToCharArray and char.ToUpper, not the ToUpper string instance method.

Uppercase First Letter

Summary. In this example, we looked at the ToUpper instance method on strings. We saw that this method uppercases all letters in strings. And it leaves non-lowercase letters completely unchanged.

Also: We touched on the invariant culture method and noted other uppercase solutions.


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