如何从一个app.config文件中设置CultureInfo.CurrentCulture? [英] How do I set CultureInfo.CurrentCulture from an App.Config file?

查看:179
本文介绍了如何从一个app.config文件中设置CultureInfo.CurrentCulture?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要通过一个app.config文件来设置我的应用程序的文化,让PT-BR自动解析日期,而不需要手动通知文化为每个操作使用。

I need to set my application's culture through an App.Config file, so that "pt-BR" is used automatically for parsing dates without the need to manually inform the culture for each operation.

据我所知,有可在的System.Web 部分里面被定义的全球化部分web.config文件,但我正在运行控制台应用程序,我不明白这一点。

As far as I know, there's a globalization section that can be defined inside the system.web section in a Web.Config file, but I'm running a console application and I can't figure this out.

你知道吗?

推荐答案

我不知道一个内置的方式从App.config中设置它,但你可以只定义一个关键在你的App.config像这样

I don't know a built-in way to set it from App.config, but you could just define a key in your App.config like this

<configuration>
    <appSettings>
        <add key="DefaultCulture" value="pt-BR" />
    </appSettings>
</configuration>

和在应用程序中读取值,并把文化

and in your application read that value and set the culture

CultureInfo culture = new CultureInfo(ConfigurationManager.AppSettings["DefaultCulture"]);
Thread.CurrentThread.CurrentCulture = culture;
Thread.CurrentThread.CurrentUICulture = culture;

这篇关于如何从一个app.config文件中设置CultureInfo.CurrentCulture?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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