.NET: Are there any differences between InvariantCulture and en-US?

后端 未结 6 1155
感情败类
感情败类 2020-11-30 06:04

Given the following two cultures:

CultureInfo c1 = InvariantCulture;
CultureInfo c2 = new CultureInfo(\"en-US\");

and i were to examine eve

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-30 06:28

    Well, if you look at what your snippet of code might produce:

    CultureInfo c1 = CultureInfo.InvariantCulture;
    CultureInfo c2 = new CultureInfo("en-US");
    
    Console.WriteLine( c1.DateTimeFormat.ShortDatePattern.ToString());
    Console.WriteLine( c2.DateTimeFormat.ShortDatePattern.ToString());
    
    Console.WriteLine( c1.DateTimeFormat.LongDatePattern.ToString());
    Console.WriteLine( c2.DateTimeFormat.LongDatePattern.ToString());
    
    Console.WriteLine( c1.NumberFormat.CurrencyDecimalDigits.ToString());
    Console.WriteLine( c2.NumberFormat.CurrencyDecimalDigits.ToString());
    
    Console.WriteLine( c1.TextInfo.IsRightToLeft.ToString());
    Console.WriteLine( c2.TextInfo.IsRightToLeft.ToString());
    

    You'll see some differences:

    MM/dd/yyyy
    M/d/yyyy
    ffffdd, dd MMMM yyyy
    ffffdd, MMMM dd, yyyy
    2
    2
    False
    False
    

    And just think, when the US loses it's backbone and decides to start using European style dates or moves to the metric system (the metric system is the tool of the devil! My car gets forty rods to the hogshead and that's the way I likes it!), the InvariantCulture can just coolly and smoothly stay the way it is. So all those dates you've stashed away in a database in text form using the InvariantCulture will continue to just work...

提交回复
热议问题