<CompatSortNLSVersion > 元素<CompatSortNLSVersion> Element

指定在执行字符串比较时,运行时应使用旧排序顺序。Specifies that the runtime should use legacy sort orders when performing string comparisons.

<configuration><configuration>
<运行时 ><runtime>
<CompatSortNLSVersion > 元素<CompatSortNLSVersion> Element

语法Syntax

<CompatSortNLSVersion    
   enabled="4096"/>  

特性和元素Attributes and Elements

下列各节描述了特性、子元素和父元素。The following sections describe attributes, child elements, and parent elements.

特性Attributes

特性Attribute 描述Description
enabled 必需的特性。Required attribute.

指定要使用其排序顺序的区域设置 ID。Specifies the locale ID whose sort order is to be used.

enabled 特性enabled Attribute

Value 描述Description
40964096 表示备选排序顺序的区域设置 ID。The locale ID that represents an alternate sort order. 在这种情况下,4096 表示.NET Framework 3.5 及更早版本的排序顺序。In this case, 4096 represents the sort order of the .NET Framework 3.5 and earlier versions.

子元素Child Elements

无。None.

父元素Parent Elements

元素Element 描述Description
configuration 公共语言运行时和 .NET Framework 应用程序所使用的每个配置文件中的根元素。The root element in every configuration file used by the common language runtime and .NET Framework applications.
runtime 包含有关运行时初始化选项的信息。Contains information about runtime initialization options.

备注Remarks

因为由执行字符串比较、 排序和大小写的操作System.Globalization.CompareInfo.NET Framework 4 中的类符合 Unicode 5.1 标准,字符串比较方法的结果如String.Compare(String, String)String.LastIndexOf(String)可能不同于.NET framework 的早期版本。Because string comparison, sorting, and casing operations performed by the System.Globalization.CompareInfo class in the .NET Framework 4 conform to the Unicode 5.1 standard, the results of string comparison methods such as String.Compare(String, String) and String.LastIndexOf(String) may differ from previous versions of the .NET Framework. 如果你的应用程序依赖于旧行为,则可以还原的字符串比较和排序规则通过包括在.NET Framework 3.5 及更早版本中使用<CompatSortNLSVersion>应用程序的配置文件中的元素。If your application depends on legacy behavior, you can restore the string comparison and sorting rules used in the .NET Framework 3.5 and earlier versions by including the <CompatSortNLSVersion> element in your application's configuration file.

重要

还原旧的字符串比较和排序规则还要求 sort00001000.dll 动态链接库在本地系统上可用。Restoring legacy string comparison and sorting rules also requires the sort00001000.dll dynamic link library to be available on the local system.

此外,通过在创建应用程序域时将字符串“NetFx40_Legacy20SortingBehavior”传递到 SetCompatibilitySwitches 方法,可以在特定的应用程序域中使用旧的字符串排序和比较规则。You can also use legacy string sorting and comparison rules in a specific application domain by passing the string "NetFx40_Legacy20SortingBehavior" to the SetCompatibilitySwitches method when you create the application domain.

示例Example

下面的示例实例化两个 String 对象,并调用 String.Compare(String, String, StringComparison) 方法以通过使用当前区域性的约定对它们进行比较。The following example instantiates two String objects and calls the String.Compare(String, String, StringComparison) method to compare them by using the conventions of the current culture.

using System;

enum StringComparisonResult
{
    precedes = -1,
    equals = 0,
    follows = 1,
};

public class Example
{
   public static void Main()
   {
      string str1 = new string( new char[] {'\u0219', '\u021B', 'a' });
      string str2 = "a";

      Console.WriteLine("{0} {1} {2} in the sort order.", 
                        str1, 
                        (StringComparisonResult) String.Compare(str1, str2, StringComparison.CurrentCulture),  
                        str2);       
   }
}
Enum StringComparisonResult As Integer
   precedes = -1
   equals = 0
   follows = 1      
End Enum

Module Example
   Public Sub Main()
      Dim str1 As String = ChrW(&h219) + ChrW(&h21B) + "a"
      Dim str2 As String = "a"

      Console.WriteLine("{0} {1} {2} in the sort order.", _
                        str1, _ 
                        CType(String.Compare(str1, str2, StringComparison.CurrentCulture), StringComparisonResult), _ 
                        str2)       
   End Sub
End Module

在.NET Framework 4 上运行示例时,它会显示以下输出。When you run the example on the .NET Framework 4, it displays the following output.

sta follows a in the sort order.  

这是完全不同于.NET Framework 3.5 上运行此示例时,将显示的输出。This is completely different from the output that is displayed when you run the example on the .NET Framework 3.5.

sta equals a in the sort order.  

但是,如果将下面的配置文件添加到该示例的目录,然后在.NET Framework 4 上运行该示例输出是与.NET Framework 3.5 上运行时生成的示例相同。However, if you add the following configuration file to the example's directory and then run the example on the .NET Framework 4, the output is identical to that produced by the example when it is run on the .NET Framework 3.5.

<?xml version ="1.0"?>  
<configuration>  
   <runtime>  
      <CompatSortNLSVersion enabled="4096"/>  
   </runtime>  
</configuration>  

请参阅See also