使用CultureAndRegionInfoBuilder更新内置的.Net文化 [英] Using CultureAndRegionInfoBuilder to update built-in .Net culture

查看:119
本文介绍了使用CultureAndRegionInfoBuilder更新内置的.Net文化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下方法更改内置的.Net文化fr-CA:

I'm attempting to change the built in .Net culture fr-CA, using the following method:

    CultureAndRegionInfoBuilder cib = new CultureAndRegionInfoBuilder("fr-CA", CultureAndRegionModifiers.Replacement);

    try
    {
        Console.WriteLine("Updating " + cib.CultureName);

        cib.NumberFormat.CurrencyGroupSeparator = ",";
        cib.NumberFormat.CurrencyDecimalSeparator = ".";
        cib.NumberFormat.NumberGroupSeparator = ",";
        cib.NumberFormat.NumberDecimalSeparator = ".";

        cib.Register();

        Console.WriteLine("Culture updated.");
    }
    catch (Exception e)
    {
        Console.WriteLine(e);
        Console.ReadKey();
    }

但是,Register()调用失败,并显示"System.InvalidOperationException:'Register'方法失败,因为自定义区域性'fr-CA'已经存在."

However, the Register() call fails with "System.InvalidOperationException: The 'Register' method failed because the custom culture 'fr-CA' already exists."

是否可以更新内置文化?根据文档( http://msdn.microsoft .com/en-us/library/system.globalization.cultureandregioninfobuilder.cultureandregioninfobuilder.aspx ),尽管我可能读错了它,但我似乎只能对其进行更新.

Is it possible to update the built-in culture? According to the docs (http://msdn.microsoft.com/en-us/library/system.globalization.cultureandregioninfobuilder.cultureandregioninfobuilder.aspx), it looks like I can just update it, though I might be reading that wrong.

推荐答案

我只需要添加:

CultureAndRegionInfoBuilder.UnRegister("fr-CA");

在Register()之前.

before Register().

这篇关于使用CultureAndRegionInfoBuilder更新内置的.Net文化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆