A class is a data structure, and localized string formatting is behavior. From a code / compiler point of view, these two things have nothing to do with eachother, and it makes no sense to set it based on "for each class." This issue relates to the scope of the code using the class, or to the code within the class itself.
Global culture information is set for each thread (using Thread.CurrentThread.CurrentCulture or CultureInfo.CurrentCulture ). One thing you can do is wrap each class method in a set / restore culture. Since the thread culture for all purposes is a global variable, this can cause problems if your class ever calls somewhere else.
The best approach if you want to specify a culture for your class to use is simply to have an instance of the culture to use as a property of the class, and then use the culture-specific overloads of most string and number formatting functions.
class MyClass { public CultureInfo Culture { get; set; } public void GetSomeString() { return new Int32().ToString(Culture); } }
Edit: Having examined your question in more detail, I think you want to do something like:
var lastCulture = Thread.CurrentThread.CurrentCulture; Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US"); try { // loop over list here } finally { Thread.CurrentThread.CurrentCulture = lastCulture; }
source share