我不完全理解 string.Equals 的第二个参数,这是因为我找不到任何例子来说明它何时会真正产生影响。例如,无论第二个参数的值如何(除了 IgnoreCase),这里给出的示例都是相同的:http://msdn.microsoft.com/en-us/library/c64xh8f9.aspx http://msdn.microsoft.com/en-us/library/c64xh8f9.aspx
我只是谈论 StringComparison.CurrentCulture、InvariantCulture 或 Ordinal 值。
我可以理解它们和 IgnoreCase 等价物之间的区别。
This http://msdn.microsoft.com/en-us/library/dd465121.aspxMSDN 页面(在 .NET Framework 中使用字符串的最佳实践)有很多有关使用字符串的信息,以下示例摘自其中:
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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)