当string.Equals的培养参数(C#)实际上有差别的例子? [英] Example of when the culture parameter of string.Equals (c#) actually makes a difference?

查看:109
本文介绍了当string.Equals的培养参数(C#)实际上有差别的例子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不完全理解string.Equals的第二个参数,这是因为我无法找到的时候会真正发挥作用的例子。例如,这里给出的例子是相同的,而不管第二参数(除了IGNORECASE)的值:
http://msdn.microsoft.com/en-us/library/c64xh8f9.aspx

I don’t fully understand the second parameter of string.Equals, and this is because I can’t find any examples of when it would actually make a difference. For example, the example given here is the same, regardless of the value of the second parameter (aside from IgnoreCase): http://msdn.microsoft.com/en-us/library/c64xh8f9.aspx

我刚才谈到的价值观StringComparison.CurrentCulture,InvariantCulture的,或序号。结果
我能理解这些和他们IGNORECASE等价物之间的差异。

I am just talking about the values StringComparison.CurrentCulture, InvariantCulture, or Ordinal.
I can understand the difference between these and their IgnoreCase equivalents.

推荐答案

的MSDN页面(最佳实践使用.NET框架中的字符串)有很多有关使用字符串和下面的例子是从它采取:

This MSDN page (Best Practices for Using Strings in the .NET Framework) has a lot of information about using strings and the following example is taken from it:

using System;
using System.Globalization;
using System.Threading;

public class Example
{
   public static void Main()
   {
      string[] values= { "able", "ångström", "apple", "Æble", 
                         "Windows", "Visual Studio" };
      Array.Sort(values);
      DisplayArray(values);

      // Change culture to Swedish (Sweden).
      string originalCulture = CultureInfo.CurrentCulture.Name;
      Thread.CurrentThread.CurrentCulture = new CultureInfo("sv-SE");
      Array.Sort(values);
      DisplayArray(values);

      // Restore the original culture.
      Thread.CurrentThread.CurrentCulture = new CultureInfo(originalCulture);
    }

    private static void DisplayArray(string[] values)
    {
      Console.WriteLine("Sorting using the {0} culture:",  
                        CultureInfo.CurrentCulture.Name);
      foreach (string value in values)
         Console.WriteLine("   {0}", value);

      Console.WriteLine();
    }
}
// The example displays the following output:
//       Sorting using the en-US culture:
//          able
//          Æble
//          ångström
//          apple
//          Visual Studio
//          Windows
//       
//       Sorting using the sv-SE culture:
//          able
//          Æble
//          apple
//          Windows
//          Visual Studio
//          ångström

这篇关于当string.Equals的培养参数(C#)实际上有差别的例子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆