Difference CreateSpecificCulture ( 'zh-cn') and new CultureInfo ( 'zh-cn') of

The following two recently discovered when looking at the code article .net resources:
Thread.CurrentThread.CurrentUICulture  =   new  CultureInfo( ' zh-cn ' );
Thread.CurrentThread.CurrentCulture 
=  CultureInfo.CreateSpecificCulture( ' zh-cn ' );

Not very understanding, through the pages of Baidu, the following results:

both are basically the same, even if the method is static CultureInfo.CreateSpecificCulture, its interior is also calling CultureInfo constructor. The difference is that when you call CultureInfo.CreateSpecificCulture CultureInfo constructor, if an error occurs, it will help you make the necessary treatment. When it finds your argument can not be established, CreateSpecificCulture checks for the beginning of this parameter name. If there will help you build. So CreateSpecificCulture nor will never go wrong.

You can try the following code:

CultureInfo ci = CultureInfo.CreateSpecificCulture("zh-");  //ok不出错
CultureInfo ci = CultureInfo.CreateSpecificCulture("zh-cn");  //ok不出错

CultureInfo ci = CultureInfo.CreateSpecificCulture("z-cn"); //出错

So CreateSpecificCulture will help you do just extra checks only.

Reproduced in: https: //www.cnblogs.com/baoposhou/archive/2007/01/09/615791.html

Guess you like

Origin blog.csdn.net/weixin_33695082/article/details/93551701