Differences between CreateSpecificCulture ('zh-cn') and new CultureInfo ('zh-cn ')

Source: Internet
Author: User
I recently read the. net Resource article and found the following two sentences: Thread. CurrentThread. CurrentUICulture = new CultureInfo ('zh-cn ');
Thread. CurrentThread. CurrentCulture = CultureInfo. CreateSpecificCulture ('zh-cn ');

I am not very familiar with it. After Baidu translation, the following results are obtained:

The two are basically the same. Even if the static CultureInfo. CreateSpecificCulture method is used, it calls the CultureInfo constructor internally. The difference is that when the CultureInfo. CreateSpecificCulture calls the CultureInfo constructor, if an error occurs, it will help you with the necessary processing. When it finds that your parameter cannot be created, CreateSpecificCulture checks whether there is a name starting with this parameter. If yes, it will help you establish it. Therefore, CreateSpecificCulture does not always cause errors.

You can try the following code:

CultureInfo ci = CultureInfo. CreateSpecificCulture ("zh-"); // OK no error
CultureInfo ci = CultureInfo. CreateSpecificCulture ("zh-cn"); // OK no error

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

Therefore, CreateSpecificCulture will only help you with additional checks.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.