CompareInfo.GetCompareInfo 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
初始化新 CompareInfo 对象。
重载
| 名称 | 说明 |
|---|---|
| GetCompareInfo(String, Assembly) |
初始化与指定区域性关联的新 CompareInfo 对象,并在指定的 Assembly区域性中使用字符串比较方法。 |
| GetCompareInfo(Int32, Assembly) |
初始化与指定区域性关联的新 CompareInfo 对象,并在指定的 Assembly区域性中使用字符串比较方法。 |
| GetCompareInfo(Int32) |
使用指定的标识符初始化与区域性关联的新 CompareInfo 对象。 |
| GetCompareInfo(String) |
使用指定名称初始化与区域性关联的新 CompareInfo 对象。 |
GetCompareInfo(String, Assembly)
初始化与指定区域性关联的新 CompareInfo 对象,并在指定的 Assembly区域性中使用字符串比较方法。
public:
static System::Globalization::CompareInfo ^ GetCompareInfo(System::String ^ name, System::Reflection::Assembly ^ assembly);
public static System.Globalization.CompareInfo GetCompareInfo(string name, System.Reflection.Assembly assembly);
static member GetCompareInfo : string * System.Reflection.Assembly -> System.Globalization.CompareInfo
Public Shared Function GetCompareInfo (name As String, assembly As Assembly) As CompareInfo
参数
- name
- String
表示区域性名称的字符串。
返回
与具有指定标识符的区域性关联的新 CompareInfo 对象,并在当前 Assembly中使用字符串比较方法。
例外
注解
Note
此方法的行为不可预知。 建议使用不采用程序集输入的此方法的版本。
参数 assembly 的类型必须与 Module.Assembly.
另请参阅
适用于
GetCompareInfo(Int32, Assembly)
初始化与指定区域性关联的新 CompareInfo 对象,并在指定的 Assembly区域性中使用字符串比较方法。
public:
static System::Globalization::CompareInfo ^ GetCompareInfo(int culture, System::Reflection::Assembly ^ assembly);
public static System.Globalization.CompareInfo GetCompareInfo(int culture, System.Reflection.Assembly assembly);
static member GetCompareInfo : int * System.Reflection.Assembly -> System.Globalization.CompareInfo
Public Shared Function GetCompareInfo (culture As Integer, assembly As Assembly) As CompareInfo
参数
- culture
- Int32
表示区域性标识符的整数。
返回
与具有指定标识符的区域性关联的新 CompareInfo 对象,并在当前 Assembly中使用字符串比较方法。
例外
assembly 是 null。
assembly 的类型无效。
注解
Note
此方法的行为不可预知。 建议应用程序使用不采用程序集输入的此方法的版本。
参数 assembly 的类型必须与 Module.Assembly.
另请参阅
适用于
GetCompareInfo(Int32)
使用指定的标识符初始化与区域性关联的新 CompareInfo 对象。
public:
static System::Globalization::CompareInfo ^ GetCompareInfo(int culture);
public static System.Globalization.CompareInfo GetCompareInfo(int culture);
static member GetCompareInfo : int -> System.Globalization.CompareInfo
Public Shared Function GetCompareInfo (culture As Integer) As CompareInfo
参数
- culture
- Int32
表示区域性标识符的整数。
返回
与具有指定标识符的区域性关联的新 CompareInfo 对象,并在当前 Assembly中使用字符串比较方法。
示例
以下示例使用不同 CompareInfo 对象比较两个字符串的部分:
CompareInfo 与西班牙(西班牙)文化相关的对象与国际排序
CompareInfo 与具有传统排序的西班牙(西班牙)文化关联的对象
与
// The following code example compares two strings using the different CompareInfo instances:
// a CompareInfo instance associated with the "Spanish - Spain" culture with international sort,
// a CompareInfo instance associated with the "Spanish - Spain" culture with traditional sort, and
// a CompareInfo instance associated with the InvariantCulture.
using System;
using System.Globalization;
public class SamplesCompareInfo {
public static void Main() {
// Defines the strings to compare.
String myStr1 = "calle";
String myStr2 = "calor";
// Uses GetCompareInfo to create the CompareInfo that uses the "es-ES" culture with international sort.
CompareInfo myCompIntl = CompareInfo.GetCompareInfo( "es-ES" );
// Uses GetCompareInfo to create the CompareInfo that uses the "es-ES" culture with traditional sort.
CompareInfo myCompTrad = CompareInfo.GetCompareInfo( 0x040A );
// Uses the CompareInfo property of the InvariantCulture.
CompareInfo myCompInva = CultureInfo.InvariantCulture.CompareInfo;
// Compares two strings using myCompIntl.
Console.WriteLine( "Comparing \"{0}\" and \"{1}\"", myStr1, myStr2 );
Console.WriteLine( " With myCompIntl.Compare: {0}", myCompIntl.Compare( myStr1, myStr2 ) );
Console.WriteLine( " With myCompTrad.Compare: {0}", myCompTrad.Compare( myStr1, myStr2 ) );
Console.WriteLine( " With myCompInva.Compare: {0}", myCompInva.Compare( myStr1, myStr2 ) );
}
}
/*
This code produces the following output.
Comparing "calle" and "calor"
With myCompIntl.Compare: -1
With myCompTrad.Compare: 1
With myCompInva.Compare: -1
*/
' The following code example compares two strings using the different CompareInfo instances:
' a CompareInfo instance associated with the "Spanish - Spain" culture with international sort,
' a CompareInfo instance associated with the "Spanish - Spain" culture with traditional sort, and
' a CompareInfo instance associated with the InvariantCulture.
Imports System.Globalization
Public Class SamplesCompareInfo
Public Shared Sub Main()
' Defines the strings to compare.
Dim myStr1 As [String] = "calle"
Dim myStr2 As [String] = "calor"
' Uses GetCompareInfo to create the CompareInfo that uses the "es-ES" culture with international sort.
Dim myCompIntl As CompareInfo = CompareInfo.GetCompareInfo("es-ES")
' Uses GetCompareInfo to create the CompareInfo that uses the "es-ES" culture with traditional sort.
Dim myCompTrad As CompareInfo = CompareInfo.GetCompareInfo(&H40A)
' Uses the CompareInfo property of the InvariantCulture.
Dim myCompInva As CompareInfo = CultureInfo.InvariantCulture.CompareInfo
' Compares two strings using myCompIntl.
Console.WriteLine("Comparing ""{0}"" and ""{1}""", myStr1, myStr2)
Console.WriteLine(" With myCompIntl.Compare: {0}", myCompIntl.Compare(myStr1, myStr2))
Console.WriteLine(" With myCompTrad.Compare: {0}", myCompTrad.Compare(myStr1, myStr2))
Console.WriteLine(" With myCompInva.Compare: {0}", myCompInva.Compare(myStr1, myStr2))
End Sub
End Class
'This code produces the following output.
'
'Comparing "calle" and "calor"
' With myCompIntl.Compare: -1
' With myCompTrad.Compare: 1
' With myCompInva.Compare: -1
适用于
GetCompareInfo(String)
使用指定名称初始化与区域性关联的新 CompareInfo 对象。
public:
static System::Globalization::CompareInfo ^ GetCompareInfo(System::String ^ name);
public static System.Globalization.CompareInfo GetCompareInfo(string name);
static member GetCompareInfo : string -> System.Globalization.CompareInfo
Public Shared Function GetCompareInfo (name As String) As CompareInfo
参数
- name
- String
表示区域性名称的字符串。
返回
与具有指定标识符的区域性关联的新 CompareInfo 对象,并在当前 Assembly中使用字符串比较方法。
例外
name 是 null。
name 是无效的区域性名称。
示例
以下示例使用不同 CompareInfo 对象比较两个字符串的部分:
CompareInfo 与西班牙(西班牙)文化相关的对象与国际排序
CompareInfo 与具有传统排序的西班牙(西班牙)文化关联的对象
与
// The following code example compares two strings using the different CompareInfo instances:
// a CompareInfo instance associated with the "Spanish - Spain" culture with international sort,
// a CompareInfo instance associated with the "Spanish - Spain" culture with traditional sort, and
// a CompareInfo instance associated with the InvariantCulture.
using System;
using System.Globalization;
public class SamplesCompareInfo {
public static void Main() {
// Defines the strings to compare.
String myStr1 = "calle";
String myStr2 = "calor";
// Uses GetCompareInfo to create the CompareInfo that uses the "es-ES" culture with international sort.
CompareInfo myCompIntl = CompareInfo.GetCompareInfo( "es-ES" );
// Uses GetCompareInfo to create the CompareInfo that uses the "es-ES" culture with traditional sort.
CompareInfo myCompTrad = CompareInfo.GetCompareInfo( 0x040A );
// Uses the CompareInfo property of the InvariantCulture.
CompareInfo myCompInva = CultureInfo.InvariantCulture.CompareInfo;
// Compares two strings using myCompIntl.
Console.WriteLine( "Comparing \"{0}\" and \"{1}\"", myStr1, myStr2 );
Console.WriteLine( " With myCompIntl.Compare: {0}", myCompIntl.Compare( myStr1, myStr2 ) );
Console.WriteLine( " With myCompTrad.Compare: {0}", myCompTrad.Compare( myStr1, myStr2 ) );
Console.WriteLine( " With myCompInva.Compare: {0}", myCompInva.Compare( myStr1, myStr2 ) );
}
}
/*
This code produces the following output.
Comparing "calle" and "calor"
With myCompIntl.Compare: -1
With myCompTrad.Compare: 1
With myCompInva.Compare: -1
*/
' The following code example compares two strings using the different CompareInfo instances:
' a CompareInfo instance associated with the "Spanish - Spain" culture with international sort,
' a CompareInfo instance associated with the "Spanish - Spain" culture with traditional sort, and
' a CompareInfo instance associated with the InvariantCulture.
Imports System.Globalization
Public Class SamplesCompareInfo
Public Shared Sub Main()
' Defines the strings to compare.
Dim myStr1 As [String] = "calle"
Dim myStr2 As [String] = "calor"
' Uses GetCompareInfo to create the CompareInfo that uses the "es-ES" culture with international sort.
Dim myCompIntl As CompareInfo = CompareInfo.GetCompareInfo("es-ES")
' Uses GetCompareInfo to create the CompareInfo that uses the "es-ES" culture with traditional sort.
Dim myCompTrad As CompareInfo = CompareInfo.GetCompareInfo(&H40A)
' Uses the CompareInfo property of the InvariantCulture.
Dim myCompInva As CompareInfo = CultureInfo.InvariantCulture.CompareInfo
' Compares two strings using myCompIntl.
Console.WriteLine("Comparing ""{0}"" and ""{1}""", myStr1, myStr2)
Console.WriteLine(" With myCompIntl.Compare: {0}", myCompIntl.Compare(myStr1, myStr2))
Console.WriteLine(" With myCompTrad.Compare: {0}", myCompTrad.Compare(myStr1, myStr2))
Console.WriteLine(" With myCompInva.Compare: {0}", myCompInva.Compare(myStr1, myStr2))
End Sub
End Class
'This code produces the following output.
'
'Comparing "calle" and "calor"
' With myCompIntl.Compare: -1
' With myCompTrad.Compare: 1
' With myCompInva.Compare: -1