sorting using an invariant culture

  • Thread starter Thread starter Tony Johansson
  • Start date Start date
T

Tony Johansson

Hi!

In a book I read it says " If sorting a collection should be independent of
a culture, the collection must be sorted with the invariant culture."

This is correct but I want to add a comment to this.

I mean that when you sort you must base the sort order on some kind of
language and the language is english.
The invariant language has some common things to the specific cultutre en-GB
except the region information of course because the invariant has no
country/region.

Can somebody give a comment about this ?

//Tony
 
Tony said:
Hi!

In a book I read it says " If sorting a collection should be independent of
a culture, the collection must be sorted with the invariant culture."

This is correct but I want to add a comment to this.

I mean that when you sort you must base the sort order on some kind of
language and the language is english. [...]

I don't think that's quite right. It's true that InvariantCulture is
primarily associated with English, mainly due I think to the fact that
certain aspects of InvariantCulture have to use _something_, and what
they use is generally the standard English/US conventions (e.g. number
formatting).

But I believe the string sorting is mainly according to the numeric
codes; you don't have to be sorting English text in order to use
InvariantCulture, and it's not really true that the sorting is based on
English. It's really based on the data as the computer sees it, without
considering cultural specifics (English or otherwise).

Pete
 
I mean that when you sort you must base the sort order on some kind of
language and the language is english.

Not really.

English only knows how to sort a-z. Does English have any rules on
how to sort Greek, or Russian, or Hindi, or Chinese characters?
The invariant locale sort is usualy by the Unicode code points.
Yes, it just happens that the ASCII section of Unicode is sorted
in the English order (a,b,c,d,e,...,y,z). So what?
It also happens that the Greek block of Unicode is sorted by the
Greek order. Does it mean that the invariant locale sorts by Greek
rules?

Now, there is true that older versions of .NET (and Windows) did not
have an invariant locale. So the recomandation was to use English
if you needed to sort something in an "invariant manner"
So it was natural (for backward compatibility) that the invariant
locale (when introduced) was the same as English (I think US).

The difference is that (in theory) the English sorting can change
(like the Norwegian sorting did), but the invariant sort is guaranteed
to stay the same.
 
Good explained!!

//Tony


Mihai N. said:
Not really.

English only knows how to sort a-z. Does English have any rules on
how to sort Greek, or Russian, or Hindi, or Chinese characters?
The invariant locale sort is usualy by the Unicode code points.
Yes, it just happens that the ASCII section of Unicode is sorted
in the English order (a,b,c,d,e,...,y,z). So what?
It also happens that the Greek block of Unicode is sorted by the
Greek order. Does it mean that the invariant locale sorts by Greek
rules?

Now, there is true that older versions of .NET (and Windows) did not
have an invariant locale. So the recomandation was to use English
if you needed to sort something in an "invariant manner"
So it was natural (for backward compatibility) that the invariant
locale (when introduced) was the same as English (I think US).

The difference is that (in theory) the English sorting can change
(like the Norwegian sorting did), but the invariant sort is guaranteed
to stay the same.
 
Back
Top