ToUpperInvariant Método
TOC
Collapse the table of content
Expand the table of content
Este artículo se tradujo automáticamente. Para ver el artículo en inglés, active la casilla Inglés. Además, puede mostrar el texto en inglés en una ventana emergente si mueve el puntero del mouse sobre el texto.
Traducción
Inglés

String.ToUpperInvariant (Método) ()

 

Devuelve una copia de este objeto String convertido en mayúsculas, aplicando las reglas de mayúsculas y minúsculas de la referencia cultural de todos los idiomas.

Espacio de nombres:   System
Ensamblado:  mscorlib (en mscorlib.dll)

public string ToUpperInvariant()

Valor devuelto

Type: System.String

Equivalente en mayúsculas de la cadena actual.

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. For more information, see the P:System.Globalization.CultureInfo.InvariantCulture property.

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

System_CAPS_noteNota

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 uppercase.

If you need the lowercase or uppercase version of an operating system identifier, such as a file name, named pipe, or registry key, use the M:System.String.ToLowerInvariant or M:System.String.ToUpperInvariant methods.

The following example defines a string array that contains a single word in a number of languages. The M:System.String.ToUpperInvariant method is used to populate the elements of a parallel array with the case-insensitive version of each word. The M:System.Array.Sort``2(``0[],``1[],System.Collections.Generic.IComparer{``0}) method is used to sort the case-sensitive array based on the order of elements in the uppercase array to ensure that elements appear in the same order regardless of language.

using System;
using System.IO;

public class Example
{
   public static void Main()
   {
      string[] words = { "Tuesday", "Salı", "Вторник", "Mardi", 
                         "Τρίτη", "Martes", "יום שלישי", 
                         "الثلاثاء", "วันอังคาร" };
      StreamWriter sw = new StreamWriter(@".\output.txt");

      // Display array in unsorted order.
      foreach (string word in words)
         sw.WriteLine(word);

      sw.WriteLine();

      // 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)
         sw.WriteLine(word);

      sw.Close();      
   }
}
// The example produces the following output:
//       Tuesday
//       Salı
//       Вторник
//       Mardi
//       Τρίτη
//       Martes
//       יום שלישי
//       الثلاثاء
//       วันอังคาร
//       
//       Mardi
//       Martes
//       Salı
//       Tuesday
//       Τρίτη
//       Вторник
//       יום שלישי
//       الثلاثاء
//       วันอังคาร

Universal Windows Platform
Disponible desde 4.5
.NET Framework
Disponible desde 2.0
Portable Class Library
Compatible con: portable .NET platforms
Silverlight
Disponible desde 4.0
Windows Phone Silverlight
Disponible desde 7.0
Windows Phone
Disponible desde 8.1
Volver al principio
Mostrar:
© 2016 Microsoft