質問

I found one interesting thing in CultureInfo class. I was writting an app in ASP.NET and I was using Thread.CurrentThread.CurrentCulture to get the current selected language and:

Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo(alias);

There was 2 places where I can set the culture of the current thread in one place I was doing like these:

  1. Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("ru");

  2. Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("ru-RU");

Then I suddenly found that the culture (1) is different then culture (2) but both of them are Russian.

Am I doing something wrong or the Microsoft is drunk?

EDIT

@Tim Schmelter

        var culture = CultureInfo.GetCultureInfo("ru");
        var culture2 = CultureInfo.GetCultureInfo("ru-RU");
        if (Equals(culture, culture2))
        {
            Console.Write(true);
            return;
        }
        Console.Write(false);

The question is - "why does Microsoft separates "ru" and "ru-RU"?

役に立ちましたか?

解決

That's because CultureInfo.GetCultureInfo("ru") returns NeutralCulture while CultureInfo.GetCultureInfo("ru-RU") returns SpecificCulture. Actually, SpecificCulture derives from NeutralCulture. So the asnwer is no, they are not the same and they have different LCIDs.

In general case you should always use SpecificCulture.

About CultureInfo suggest reading this MSDN article.

他のヒント

The ru culture is neutral, meaning that it cannot be used in formatting and parsing. The ru-RU culture, on the other hand, is specific (demo #1), so you can use it to format and parse your data.

Comparing the pages for the two cultures shows that ru has a subset of settings provided by ru-RU.

Among other things, trying to set a neutral culture as a thread's current culture leads to exceptions (demo #2 on Mono, does not crash on .NET 4.5).

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top