如何为整个 C# 应用程序设置默认文化信息 [英] how to set default culture info for entire c# application

查看:22
本文介绍了如何为整个 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 可按线程设置,如下所述有没有办法为整个应用程序设置文化?所有当前线程和新线程?.你根本无法改变InvariantCulture.

CurrentUICulture and CurrentCulture are settable per thread as discussed here Is there a way of setting culture for a whole application? All current threads and new threads?. 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天全站免登陆