在C#是什么ToUpper的()和ToUpperInvariant()之间的区别? [英] In C# what is the difference between ToUpper() and ToUpperInvariant()?

查看:3593
本文介绍了在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是不是我。

The canonical example is Turkey, where the upper case of "i" isn't "I".

样code示出了差异:

Sample code showing the difference:

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);
    }
}

更多关于土耳其,看到这个土耳其测试博客帖子

我也不会感到惊讶地听到,还有许多其他资本化发行省略周围人物等,这只是一个例子,我知道了我的头顶......部分原因是它在Java中,其中年前咬了我我在上层套管的字符串,并将其与邮件比较。这并不在土耳其的工作这么好......

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()之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆