In C# what is the difference between ToUpper() and ToUpperInvariant()?(在 C# 中,ToUpper() 和 ToUpperInvariant() 有什么区别?)
问题描述
在C#中,ToUpper()
和ToUpperInvariant()
有什么区别?
In C#, what is the difference between ToUpper()
and ToUpperInvariant()
?
您能举一个结果可能不同的例子吗?
Can you give an example where the results might be different?
推荐答案
ToUpper
使用当前文化.ToUpperInvariant
使用不变的文化.
ToUpper
uses the current culture. ToUpperInvariant
uses the invariant culture.
典型的例子是土耳其,其中i"的大写不是I".
The canonical example is Turkey, where the upper case of "i" isn't "I".
显示差异的示例代码:
using System;
using System.Drawing;
using System.Globalization;
using System.Threading;
using System.Windows.Forms;
public class Test
{
[STAThread]
static void Main()
{
string invariant = "iii".ToUpperInvariant();
CultureInfo turkey = new CultureInfo("tr-TR");
Thread.CurrentThread.CurrentCulture = turkey;
string cultured = "iii".ToUpper();
Font bigFont = new Font("Arial", 40);
Form f = new Form {
Controls = {
new Label { Text = invariant, Location = new Point(20, 20),
Font = bigFont, AutoSize = true},
new Label { Text = cultured, Location = new Point(20, 100),
Font = bigFont, AutoSize = true }
}
};
Application.Run(f);
}
}
有关土耳其语的更多信息,请参阅此 土耳其测试博文.
For more on Turkish, see this Turkey Test blog post.
听到关于省略字符等还有各种其他大写问题,我不会感到惊讶.这只是我知道的一个例子......部分是因为它在几年前在 Java 中咬了我,在哪里我将字符串大写并将其与MAIL"进行比较.这在土耳其并不奏效......
I wouldn't be surprised to hear that there are various other capitalization issues around elided characters etc. This is just one example I know off the top of my head... partly because it bit me years ago in Java, where I was upper-casing a string and comparing it with "MAIL". That didn't work so well in Turkey...
这篇关于在 C# 中,ToUpper() 和 ToUpperInvariant() 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 C# 中,ToUpper() 和 ToUpperInvariant() 有什么区别?


- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 输入按键事件处理程序 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01