如何为整个C#应用程序的默认区域性信息 [英] how to set default culture info for entire c# application

查看:491
本文介绍了如何为整个C#应用程序的默认区域性信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要为这个类或整个应用程序的默认区域性的信息。

I want to set default culture info for that class or for entire application.

例如在土耳其3,2 =英文3.2

For example in Turkey 3,2 = in english 3.2

这样的应用程序使用我的地方,但我希望它为默认

so application uses my local but i want it to use as default

System.Globalization.CultureInfo.InvariantCulture

如何将其设置为默认为特定类或整个应用程序

How can i set it to that as default for that specific class or for entire application

推荐答案

不为整个应用程序或特定的类。

Not for entire application or particular class.

的CurrentUICulture和的CurrentCulture是每个线程可设置为这里讨论设置的CurrentCulture和的CurrentUICulture应用程序的 。你不能改变 InvariantCulture的所有

CurrentUICulture and CurrentCulture are settable per thread as discussed here Setting CurrentCulture and CurrentUICulture of an application. You can't change InvariantCulture at all.

示例代码更改为文化当前线程:

Sample code to change cultures for current thread:

CultureInfo ci = new CultureInfo(theCultureString);
Thread.CurrentThread.CurrentCulture = ci;
Thread.CurrentThread.CurrentUICulture = ci;

有关类,你可以设置/还原重要方法里面的文化,但它会显著安全使用适当的覆盖该拿文化作为一个参数最格式相关的方法:

For class you can set/restore culture inside critical methods, but it would be significantly safe to use appropriate overrides for most formatting related methods that take culture as one of arguments:

(3.3).ToString(new CultureInfo("fr-FR"))

这篇关于如何为整个C#应用程序的默认区域性信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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