Changing Case of string in C#

String offers two convenient methods that enable us to change the case of letters within a string.these are ToUpper() and ToLower().

public string ToUpper()
public string ToLower()

ToUpper() uppercases all letters within the invoking string. ToLower() lowercases all letters within the invoking string.

 

C# added two another version of these methods that allow us to specify cultural settings: ToUpperInvariant() and ToLowerInvariant().

public string ToUpperInvariant()
public string ToLowerInvariant()

they work same as ToUpper() and ToLower() except they use the invariant cultural to perform transformations to upper or lower cases.

Example:

string str = “AuthorCode”;

string strUpper = str.ToUpper();
//value of strUpper=”AUTHORCODE”

string strlower = str.ToLower();
//value of strlower =”authorcode”