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() 有什么区别?
基础教程推荐
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
