question

HaraldRenFlasch-4704 avatar image
0 Votes"
HaraldRenFlasch-4704 asked JackJJun-MSFT commented

CultureInfo.GetCultures(CultureTypes.AllCultures) vs. new CultureInfo(name)

According to MSDN documentation CultureInfo.GetCultures(CultureTypes.AllCultures) returns all cultures which are supported on the machine where the code is running.

For me (on my Windows 10 Developer machine) CultureInfo.GetCultures(CultureTypes.AllCultures) returns 813(!) culture info objects. That's a lot... Can't imagine that so many "language packs"(?) are installed on my machine wich would be waste of resources... but let's accept this....

For example zh-CN is not returned by CultureInfo.GetCultures(CultureTypes.AllCultures) ... But when I execute new CultureInfo("zh-CN") I get a valid culture info object with all values set... Why?

Using .NET6 Core.



dotnet-csharp
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@HaraldRenFlasch-4704, is any update? It seems that Castorix31's answer is correct. Do you have time to check it?

0 Votes 0 ·

1 Answer

Castorix31 avatar image
1 Vote"
Castorix31 answered

You can see the source code at corert

In resume, GetCultures calls EnumSystemLocalesEx or ICU
and new CultureInfo calls GetCultureData and if not found, calls CreateCultureData (which calls CreateCultureWithInvariantData and other code)





5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.