C# ToLower() Method


The ToLower() method in C# is used to return a copy of this string converted to lowercase.

Syntax

The syntax is as follows -

public string ToLower ();

Example

Let us now see an example -

 Live Demo

using System;
public class Demo {
   public static void Main(String[] args) {
      string str1 = "WELCOME!";
      string str2 = "Thisisit!";
      char[] arr1 = str1.ToCharArray(3,2);
      char[] arr2 = str2.ToCharArray(2,2);
      Console.WriteLine("String1 = "+str1);
      Console.WriteLine("String1 ToLower = "+str1.ToLower());
      Console.WriteLine("String1 Substring from index4 = " + str1.Substring(4, 4));
      Console.Write("Character array...String1 =");
      for (int i = 0; i < arr1.Length; i++)
         Console.Write(" " + arr1[i]);
      Console.WriteLine("

String2 = "+str2);       Console.WriteLine("String2 ToLower = "+str2.ToLower());       Console.WriteLine("String2 Substring from index2 = " + str2.Substring(0, 5));       Console.Write("Character array...String2 =");       for (int i = 0; i < arr2.Length; i++)          Console.Write(" " + arr2[i]);    } }

Output

String1 = WELCOME!
String1 ToLower = welcome!
String1 Substring from index4 = OME!
Character array...String1 = C O
String2 = Thisisit!
String2 ToLower = thisisit!
String2 Substring from index2 = Thisi
Character array...String2 = i s

Example

Let us now see another example -

 Live Demo

using System;
using System.Globalization;
public class Demo {
   public static void Main(String[] args) {
      string str1 = "ABCD!";
      string str2 = "@#$PQRSTUV!";
      Console.WriteLine("String1 = "+str1);
      Console.WriteLine("String1 ToLower = "+str1.ToLower(new CultureInfo("en-US", false)));
      Console.WriteLine("String1 Substring from index4 = " + str1.Substring(2, 2));
      Console.WriteLine("

String2 = "+str2);       Console.WriteLine("String2 ToLower = "+str2.ToLower(new CultureInfo("en-US", false)));       Console.WriteLine("String2 Substring from index2 = " + str2.Substring(0, 5));    } }

Output

String1 = ABCD!
String1 ToLower = abcd!
String1 Substring from index4 = CD
String2 = @#$PQRSTUV!
String2 ToLower = @#$pqrstuv!
String2 Substring from index2 = @#$PQ

Updated on: 03-Dec-2019

204 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements