Export (0) Print
Expand All
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

String.ToLowerInvariant Method

Returns a copy of this string converted to lowercase using the casing rules of the invariant culture.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

public string ToLowerInvariant()

Return Value

Type: System.String
The lowercase equivalent of the current string.

The invariant culture represents a culture that is culture-insensitive. It is associated with the English language but not with a specific country or region.

If your application depends on the case of a string changing in a predictable way that is unaffected by the current culture, use the ToLowerInvariant method. The ToLowerInvariant method is equivalent to ToLower(CultureInfo.InvariantCulture). The method is recommended when a collection of strings must appear in a predictable order in a user interface control.

NoteNote:

   This method does not modify the value of the current instance. Instead, it returns a new string in which all characters in the current instance are converted to lowercase.

The following example defines a string array that contains a single word in a number of languages. The ToLowerInvariant method is used to populate the elements of a parallel array with the case-insensitive version of each word. The Array.Sort<TKey, TValue>(TKey[], TValue[], IComparer<TKey>) method is used to sort the case-sensitive array based on the order of elements in the lowercase array to ensure that elements appear in the same order regardless of language.


using System;

public class Example
{
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      string[] words = { "Tuesday", "Salı", "Вторник", "Mardi", 
                         "Τρίτη", "Martes", "יום שלישי", 
                         "الثلاثاء", "วันอังคาร" };
      // Display array in unsorted order.
      foreach (string word in words)
         outputBlock.Text += word + "\n";
      outputBlock.Text += "\n";

      // Create parallel array of words by calling ToUpperInvariant.
      string[] upperWords = new string[words.Length];
      for (int ctr = words.GetLowerBound(0); ctr <= words.GetUpperBound(0); ctr++)
         upperWords[ctr] = words[ctr].ToUpperInvariant();

      // Sort the words array based on the order of upperWords.
      Array.Sort(upperWords, words, StringComparer.InvariantCulture);

      // Display the sorted array.
      foreach (string word in words)
         outputBlock.Text += word + "\n";
   }
}
// The example displays the following output:
//       Tuesday
//       Salı
//       Вторник
//       Mardi
//       Τρίτη
//       Martes
//       יום שלישי
//       الثلاثاء
//       วันอังคาร
//       
//       Mardi
//       Martes
//       Salı
//       Tuesday
//       Τρίτη
//       Вторник
//       יום שלישי
//       الثلاثاء
//       วันอังคาร


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2015 Microsoft