string.Equals(c#)的culture参数何时实际产生影响的示例?
发布时间:2020-12-15 07:47:03 所属栏目:百科 来源:网络整理
导读:我不完全理解string.Equals的第二个参数,这是因为我找不到任何实际会产生影响的例子.例如,这里给出的示例是相同的,无论第二个参数的值如何(除了IgnoreCase): http://msdn.microsoft.com/en-us/library/c64xh8f9.aspx 我只是在讨论StringComparison.CurrentC
我不完全理解string.Equals的第二个参数,这是因为我找不到任何实际会产生影响的例子.例如,这里给出的示例是相同的,无论第二个参数的值如何(除了IgnoreCase):
http://msdn.microsoft.com/en-us/library/c64xh8f9.aspx 我只是在讨论StringComparison.CurrentCulture,InvariantCulture或Ordinal的值. 解决方法
This MSDN页面(在.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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |