C# String ToLowerInvariant()

The ToLowerInvariant() method is a part of the System.String class in C#. It converts all the characters in a string to lowercase using the invariant culture rules.

Here’s an example usage:

string str = "Hello, World!";
string lowercaseStr = str.ToLowerInvariant();

Console.WriteLine(lowercaseStr); // Output: hello, world!

In the above example, the ToLowerInvariant() method is called on the str string variable, which converts all the characters to lowercase. The resulting lowercase string is then assigned to the lowercaseStr variable and displayed on the console.

Signature:

The signature of the ToLowerInvariant() method in C# is as follows:

public string ToLowerInvariant()

The ToLowerInvariant() method does not take any parameters. It returns a new string that is a copy of the original string with all the characters converted to lowercase using the invariant culture rules.

Here’s an example usage of the method:

string str = "Hello, World!";
string lowercaseStr = str.ToLowerInvariant();

Console.WriteLine(lowercaseStr); // Output: hello, world!

In this example, the ToLowerInvariant() method is called on the str string object, and the resulting lowercase string is stored in the lowercaseStr variable.

Parameter:

The ToLowerInvariant() method in C# does not accept any parameters. It is a parameterless method that converts all the characters in a string to lowercase using the invariant culture rules.

Here’s an updated example usage:

string str = "Hello, World!";
string lowercaseStr = str.ToLowerInvariant();

Console.WriteLine(lowercaseStr); // Output: hello, world!

In the example above, the ToLowerInvariant() method is called on the str string variable. It does not take any arguments and returns a new string that contains the lowercase representation of the original string, based on the invariant culture rules. The resulting lowercase string is then assigned to the lowercaseStr variable and displayed on the console.

Return:

The ToLowerInvariant() method in C# returns a new string that is a copy of the original string with all the characters converted to lowercase using the invariant culture rules. It does not modify the original string.

Here’s an example that demonstrates the return value of the ToLowerInvariant() method:

string str = "Hello, World!";
string lowercaseStr = str.ToLowerInvariant();

Console.WriteLine(lowercaseStr); // Output: hello, world!

Console.WriteLine(str); // Output: Hello, World!

In this example, the ToLowerInvariant() method is called on the str string object, and the resulting lowercase string is stored in the lowercaseStr variable. The ToLowerInvariant() method returns the lowercase version of the string without modifying the original str variable. As a result, when we output the str variable, it remains unchanged and still contains the original string “Hello, World!”.

C# String ToLowerInvariant() Method Example:

Certainly! Here’s an example that demonstrates the usage of the ToLowerInvariant() method in C#:

using System;

class Program
{
    static void Main()
    {
        string input = "Hello, World!";
        string lowercase = input.ToLowerInvariant();

        Console.WriteLine("Original string: " + input);
        Console.WriteLine("Lowercase string: " + lowercase);
    }
}

Output:

Original string: Hello, World!
Lowercase string: hello, world!

In the above example, the ToLowerInvariant() method is called on the input string, which converts all the characters to lowercase using the invariant culture rules. The resulting lowercase string is stored in the lowercase variable.

Then, the original string (input) and the lowercase string (lowercase) are displayed on the console.

Note that the ToLowerInvariant() method does not modify the original string (input), but rather returns a new string with the lowercase representation.