原贴地址:http://www.soaspx.com/dotnet/csharp/csharp_20110506_7607.html
CultureInfo简述
static
readonly
string
[] CultureSources
=
{
"en-us"
,
"zh-cn"
,
"ar-iq"
,
"de-de"
};
static
readonly
Random
Ran
=
new
Random
(
Environment
.
TickCount);
static
void
Main()
{
Console
.
WriteLine(
"
数据中心开始接受客户端数据:
"
);
for
(
int
i
=
0
; i
<
CultureSources
.
Length; i
++
)
ThreadPool
.
QueueUserWorkItem(Client, i);
Console
.
ReadKey(
true
);
Console
.
WriteLine(
""
);
Console
.
WriteLine(
"
数据中心:
…………"
);
}
static
void
Client(
object
obj)
{
int
id
=
(
int
)obj;
Thread
.
Sleep(Ran
.
Next(
1000
));
CultureInfo
cul
=
CultureInfo
.
GetCultureInfo(CultureSources[id]);
Thread
.
CurrentThread
.
CurrentCulture
=
cul;
Console
.
WriteLine(
"
某客户端操作系统语言设置
{0}\n
传送数据:
{1}\n"
, cul
.
DisplayName,
new
DateTime
(
1990
,
10
,
27
)
.
ToShortDateString());
}
|
Console
.
WriteLine(
"
某客户端操作系统语言设置
{0}\n
传送数据:
{1}\n"
, cul
.
DisplayName,
new
DateTime
(
1990
,
10
,
27
)
.
ToString(
CultureInfo
.
InvariantCulture
.
DateTimeFormat
.
ShortDatePattern,
CultureInfo
.
InvariantCulture));
|
static
void
Main()
{
string
[] strs
=
{
"a"
,
"A"
,
"b"
,
"B"
,
"abc"
,
"ab"
,
"aB"
,
"AB"
,
"Ab"
,
"aaa"
};
Console
.
WriteLine(
"en-US"
);
Array
.
Sort
<
string
>
(strs,
StringComparer
.
Create(
CultureInfo
.
GetCultureInfo(
"en-us"
),
false
));
Console
.
WriteLine(
String
.
Join(
" < "
, strs));
Console
.
WriteLine(
"zh-CN"
);
Array
.
Sort
<
string
>
(strs,
StringComparer
.
Create(
CultureInfo
.
GetCultureInfo(
"zh-CN"
),
false
));
Console
.
WriteLine(
String
.
Join(
" < "
, strs));
Console
.
WriteLine(
"Ordinal"
);
Array
.
Sort
<
string
>
(strs,
StringComparer
.
Ordinal);
Console
.
WriteLine(
String
.
Join(
" < "
, strs));
Console
.
WriteLine(
"Invariant"
);
Array
.
Sort
<
string
>
(strs,
StringComparer
.
InvariantCulture);
Console
.
WriteLine(
String
.
Join(
" < "
, strs));
}
|
en-US
a < A < aaa < ab < aB < Ab < AB < abc < b < B
zh-CN
a < A < aaa < ab < aB < Ab < AB < abc < b < B
Ordinal
A < AB < Ab < B < a < aB < aaa < ab < abc < b
Invariant
a < A < aaa < ab < aB < Ab < AB < abc < b < B
|