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() 有什么区别?
基础教程推荐
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
- 将数据集转换为列表 2022-01-01
- 如果条件可以为空 2022-01-01
- 获取C#保存对话框的文件路径 2022-01-01
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
- 从 C# 控制相机设备 2022-01-01
