String.ToUpperInvariant 方法   
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
返回此 String 对象的转换为大写形式的副本,返回时使用固定区域性的大小写规则。
public:
 System::String ^ ToUpperInvariant();public string ToUpperInvariant();member this.ToUpperInvariant : unit -> stringPublic Function ToUpperInvariant () As String返回
当前字符串的大写形式。
示例
以下示例定义一个字符串数组,其中包含多种语言的单个单词。 方法 ToUpperInvariant 用于使用每个单词的不区分大小写的版本填充并行数组的元素。 方法 Array.Sort<TKey,TValue>(TKey[], TValue[], IComparer<TKey>) 用于根据大写数组中元素的顺序对区分大小写的数组进行排序,以确保无论语言如何,元素都以相同的顺序显示。
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
//       Τρίτη
//       Вторник
//       יום שלישי
//       الثلاثاء
//       วันอังคาร
open System
open System.IO
do
    let words = 
        [| "Tuesday"; "Salı"; "Вторник"; "Mardi" 
           "Τρίτη"; "Martes"; "יום שלישי" 
           "الثلاثاء"; "วันอังคาร" |]
    use sw = new StreamWriter(@".\output.txt")
        
    // Display array in unsorted order.
    for word in words do
        sw.WriteLine word
    sw.WriteLine()
    // Create parallel array of words by calling ToUpperInvariant.
    let upperWords = words |> Array.map (fun x -> x.ToUpperInvariant())
    
    // Sort the words array based on the order of upperWords.
    Array.Sort(upperWords, words, StringComparer.InvariantCulture)
    
    // Display the sorted array.
    for word in words do
        sw.WriteLine word
    sw.Close()      
// The example produces the following output:
//       Tuesday
//       Salı
//       Вторник
//       Mardi
//       Τρίτη
//       Martes
//       יום שלישי
//       الثلاثاء
//       วันอังคาร
//       
//       Mardi
//       Martes
//       Salı
//       Tuesday
//       Τρίτη
//       Вторник
//       יום שלישי
//       الثلاثاء
//       วันอังคาร
Imports System.IO
Module Example
   Public Sub Main()
      Dim words() As String = { "Tuesday", "Salı", "Вторник", "Mardi", _
                                "Τρίτη", "Martes", "יום שלישי", _
                                "الثلاثاء", "วันอังคาร" }
      Dim sw As New StreamWriter(".\output.txt")
      
      ' Display array in unsorted order.
      For Each word As String In words
         sw.WriteLine(word)
      Next
      sw.WriteLine()
      ' Create parallel array of words by calling ToUpperInvariant.
      Dim upperWords(words.Length - 1) As String
      For ctr As Integer = words.GetLowerBound(0) To words.GetUpperBound(0)
         upperWords(ctr) = words(ctr).ToUpperInvariant()
      Next
      
      ' Sort the words array based on the order of upperWords.
      Array.Sort(upperWords, words, StringComparer.InvariantCulture)
      
      ' Display the sorted array.
      For Each word As String In words
         sw.WriteLine(word)
      Next
      
      sw.Close()
   End Sub
End Module
' The example produces the following output:
'       Tuesday
'       Salı
'       Вторник
'       Mardi
'       Τρίτη
'       Martes
'       יום שלישי
'       الثلاثاء
'       วันอังคาร
'       
'       Mardi
'       Martes
'       Salı
'       Tuesday
'       Τρίτη
'       Вторник
'       יום שלישי
'       الثلاثاء
'       วันอังคาร
注解
固定区域性表示不区分区域性的区域性。 它与英语相关联,但不与特定国家或地区相关联。 有关更多信息,请参见 CultureInfo.InvariantCulture 属性。
如果应用程序依赖于字符串以不受当前区域性影响且以可预测的方式更改的情况,请使用 ToUpperInvariant 方法。 方法 ToUpperInvariant 等效于 ToUpper(CultureInfo.InvariantCulture)。 当字符串集合必须以可预测的顺序出现在用户界面控件中时,建议使用 方法。
注意
此方法不会修改当前实例的值。 相反,它返回一个新字符串,其中当前实例中的所有字符都转换为大写。
如果需要操作系统标识符的小写或大写版本(如文件名、命名管道或注册表项),请使用 ToLowerInvariant 或 ToUpperInvariant 方法。