how to set default culture info for entire c# application

前端 未结 3 1508
余生分开走
余生分开走 2020-12-13 12:26

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

For example in Turkey 3,2 = in english 3.2

so application uses my local but i wa

3条回答
  •  囚心锁ツ
    2020-12-13 12:45

    Not for entire application or particular class.

    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"))
    

提交回复
热议问题