Why isn't there a culture enum?
Asked Answered
S

4

11

Greetings,

I was wondering why there isn't a pre-set enum for cultures in C#? Since the cultures never change and are always like "nl-NL, en-GB, en-US".. why not make a enum for it to make things just a little bit easy'r ?

[edit]

As stated cultures do change.. but not all. Why not make a enum / class type which holds all the cultures and gives the possibility to add / change them ?

Seclude answered 20/4, 2011 at 7:26 Comment(1)
Re the edit... because very little code would need to talk to them all as (say) public fields. Individually, a string works fine - and en-masse, you probably aren't using static code anyway, but would be looking them up by key - which is what is provided.Utilitarian
L
16

"Since the cultures never change"

Don't they? This article (Microsoft .NET Framework 4: What is New in Globalization) disagrees. In the past 5 years alone, a lot has changed in the region of Serbia for example, leading to new Cultures.

In the real world, the globalization information is constantly changing because of cultural developments in the local markets, because of new standards which update the culture sensitive information frequently, or because Microsoft finds more accurate information about different markets or expands into more markets.

Microsoft .NET Framework 4 supports a minimum of 354 cultures compared to a minimum of 203 cultures in the previous release. Many of those cultures are neutrals that were added to complete the parent chain to the root neutral culture.

For example, three Inuktitut neutrals were added to the already existing cultures Inuktitut (Syllabics, Canada) and Inuktitut (Latin, Canada)

Also, I guess an enum itself does not make sense. A CultureInfo is much more than just a name, and a lookup offers more flexibility and independence from any political changes, of which there are many more than we usually realize.

Levana answered 20/4, 2011 at 7:30 Comment(2)
I hate to be a bother but that link appears to have died. Would you mind updating it? Looked like an interesting read.Suds
@Suds Thanks, I've changed it to a link to archive.org and pulled out a quote.Levana
M
8

Enumerations are fixed at compile time.

But the set of cultures varies at runtime:

  • Different OS versions support different cultures
  • OS updates (Service Packs, Language Interface Packs, ...) can add cultures
  • Later .NET versions support more cultures (build assembly for one version and use it with another).
Maeganmaelstrom answered 20/4, 2011 at 7:30 Comment(0)
U
4

They do change, albeit slowly. In any case, they predate C#, so making them into an enum at this point would be kludgery. Like making POSIX system calls into an enum, which I did in postForth, but knew it was wrong when I did it.

Unitarianism answered 20/4, 2011 at 7:29 Comment(0)
P
4

In addition to them changing, as suggested by others, you can create your own cultures and they would be conspicuously absent from the enum since you can't add items to it.

Preparatory answered 20/4, 2011 at 7:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.