Uppercase and Lowercase Strings in C#

C# String has ToUpper() and ToLower() methods to convert a string to uppercase and lowercase. This sample code demonstrates how to convert a string into lowercase string or uppercase string in C#.

The String.ToUpper() and String.ToLower() methods in C# and .NET convert a string into an uppercase and a lowercase string respectively. These methods are easy to use.
 
The following code sample converts to string into uppercase and lowercase strings. 
  1. string author = "Mahesh Chand";  
  2. string bio = "Mahesh Chand is a founder of C# Corner.";  
  3.   
  4. // Covert everything to uppercase  
  5. string ucaseAuthor = author.ToUpper();          
  6. Console.WriteLine($"Uppercase: {ucaseAuthor}");  
  7.   
  8. // Covert everything to lowercase  
  9. string lcaseAuthor = author.ToLower();  
  10. Console.WriteLine($"Lowercase: {lcaseAuthor}");  
  11.   
  12. // We can direct convert to uppercase or lowercase  
  13. Console.WriteLine(bio.ToLower());  
  14. Console.WriteLine(bio.ToUpper());  
The output from above code is as shown below.
 
 
 
Convert first letter of a string to uppercase
 
The following code snippet makes a string's first letter uppercase.  
  1. // convert first letter of a string uppercase  
  2. string name = "chris love";  
  3. if (!string.IsNullOrEmpty(name))  
  4. {  
  5.     name = char.ToUpper(name[0]) + name.Substring(1);  
  6. }  
  7. Console.WriteLine($"String with first letter uppercase: {name} ");  
Convert a part of string to lowercase
 
The following code snippet converts a part of string to lowercase.  
  1. // Convert a part of string to lowercase  
  2. string uName = "MAHESH CHAND";  
  3. string updatedName = uName.Substring(0, 1).ToUpper() + uName.Substring(1).ToLower();  
  4. Console.WriteLine(updatedName);  
Make every first character of each word in a string uppercase
 
TextInfo.ToTitleCase method can be used to make every word in a string starts with a uppercase character.  
  1. // Every word start with uppercase  
  2. string aName = "mahesh chand beniwal";  
  3. string fullName = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(aName);  
  4. Console.WriteLine(fullName);  
To learn more about C# strings, check out String In C# tutorial to learn more about strings and how to work with strings in C#.