Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 双ToString(“C”)特定于区域性_C#_Asp.net_Cultureinfo - Fatal编程技术网

C# 双ToString(“C”)特定于区域性

C# 双ToString(“C”)特定于区域性,c#,asp.net,cultureinfo,C#,Asp.net,Cultureinfo,我知道这是有效的(): 但我的代码中有以下代码: System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-GB"); System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-GB"); 在我的aspx网络表单中,我想使用doubl

我知道这是有效的():

但我的代码中有以下代码:

System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-GB");
System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-GB");
在我的aspx网络表单中,我想使用
double.tostring(“C”)
这样就没有文化信息了。因为它是在当前线程上设置的。但是本地机器是
nl-nl
。CurrentThread在代码隐藏中设置为en GB,但ValueTaSign仍然是欧元符号而不是英镑


我错过什么了吗?或者是否需要将tostring的重载与cultureinfo一起使用?换句话说,我是否必须重写所有双ToString才能使用cultureinfo?

确保在页面生命周期中足够快地初始化区域性。事实上,甚至有一种方法专门用于此目的,可供您重写:

基于cookie的示例:

    protected override void InitializeCulture()
    {
        var cookie = Request.Cookies[WebConfigurationManager.AppSettings["LocaleCookieName"]];
        if (cookie != null)
            Culture = UICulture = cookie.Value;
    }

无需调用基本方法,有关详细信息,请参阅文档。

在codebehind中的何处指定
CurrentCulture
?然而,你想要什么还不是很清楚。你说第一个片段有效,那么1)为什么不使用它?2.)你想要英镑而不是欧元符号,那么为什么要使用
x.ToString(“C”,CultureInfo.CreateSpecificCulture(“nl nl”)
?那么只要使用
x.ToString(“C”)
就可以了,如果你确定你当前的线程文化是
en GB
。@xanatos:我以为整个生命周期都是从同一个线程处理的,你有链接吗?蒂姆,因为我的aspx文件中有很多双ToString。我喜欢在一个中心位置设置线程的区域性,我这样做了,但不影响aspx文件的渲染@我敢肯定,索尼格尔是这么说的。但它不起作用。和Xanatos,我喜欢根据登录用户进行切换。并不是所有的用户都可以,只是用英语来表示英镑,否则就用欧元s@JPHellemons:您尚未回答在何处更改当前区域性的问题。您必须在
Page\u PreInit
中执行此操作,而不是
Init
Load
。另外,在哪里使用
double.tostring(“C”)
?你能把代码显示出来吗,是在aspx上还是在codebehind中?可惜这在我的主页上是不可能的。我将测试它一次aspx@JPHellemons您可能需要重新考虑您的设计。大多数应用程序将使用一个或多个
Page
子类,这些子类将派生任意页面。如果使用某个母版页的所有页面都需要相同的
页面
超类型,那么您可以仅为这些页面创建一个超类型。通常,您会发现母版页关系与
page
类型层次结构没有内在的联系,在这种情况下,额外的灵活性就派上了用场。
    protected override void InitializeCulture()
    {
        var cookie = Request.Cookies[WebConfigurationManager.AppSettings["LocaleCookieName"]];
        if (cookie != null)
            Culture = UICulture = cookie.Value;
    }