- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Arithmetic Operators
- C# - Assignment Operators
- C# - Relational Operators
- C# - Logical Operators
- C# - Bitwise Operators
- C# - Miscellaneous Operators
- C# - Operators Precedence
- C# Conditional Statements
- C# - Decision Making
- C# - If
- C# - If Else
- C# - Nested If
- C# - Switch
- C# - Nested Switch
- C# - Switch Expressions
- C# Control Statements
- C# - Loops
- C# - For Loop
- C# - While Loop
- C# - Do While Loop
- C# - Nested Loops
- C# - Break
- C# - Continue
- C# - Foreach Loop
- C# - Goto Statement
- C# OOP & Data Handling
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - LINQ
- C# - IEnumerable vs IEnumerator
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Tasks and Parallel Programming
- C# - Multithreading
- C# - Extension Methods
C# String - ToLower() Method
The C# String ToLower() method converts all character in a string to lower case and is used to perform case-insensitive operations, normalize strings for comparison, or handle user input.
Syntax
Following are the syntax of the C# string ToLower() method −
Default Syntax −
This syntax return copy of the current string converted to lower case.
public string ToLower();
Parametrised Syntax −
This syntax returns a copy of this string converted to lowercase, using the casing rules of the specified culture.
public string ToLower (System.Globalization.CultureInfo? culture);
Parameters
This method accepts the following parameters −
culture: This is an object that supplies culture-specific wrapper rules. If culture is null, the current culture is used.
Return Value
This method returns a string that is in lowercase equivalent to the current string.
Example 1: Using ToLower with Current Culture
Following is a basic example of the ToLower() method to convert the string into lowercase with the current culture −
using System;
class Program {
public static void Main() {
string str = "Hello, tpians!";
string ToLower = str.ToLower();
Console.Write("Converted String: "+ ToLower);
}
}
Output
Following is the output −
Converted String: hello, tpians!
Example 2: Using ToLower(CultureInfo) with a specific culture
Let's look at another example. Here, we use the parametrised ToLower() method to convert a string into lowercase with specific culture −
using System;
using System.Globalization;
class Program {
static void Main() {
// Turkish character ''
string str = "stanbul";
//use InvariantCulture
string lowerInvariant = str.ToLower(CultureInfo.InvariantCulture);
string lowerTurkish = str.ToLower(new CultureInfo("tr-TR"));
Console.WriteLine(lowerInvariant);
Console.WriteLine(lowerTurkish);
}
}
Output
Following is the output −
stanbul istanbul
Example 3: Case-Insensitive Comparisons
In this example, we convert the string into lowercase using the ToLower() method. We then compare string −
using System;
class Program {
public static void Main() {
string userInput = "Admin";
if (userInput.ToLower() == "admin") {
Console.WriteLine("Access granted!");
}
}
}
Output
Following is the output −
Access granted!