.NET Tips and Tricks

Blog archive

Set Culture Information in One Step in .NET Framework 4.5

In the .NET Framework 4.0 or earlier, you have to set the culture for each thread individually. At the very least, this meant setting the CurrentThread object's CurrentCulture and CurrentUICulture properties. In the .NET Framework 4.5, you can do it in just two lines of code for every thread in your application, using the CultureInfo object.

The syntax is a little "un-obvious": You must first instantiate a CultureInfo object, passing a culture code. You then pass that object to a static method called DefaultThreadCurrentCulture, also on the CultureInfo object.

Typical code looks like this:

Dim ci As CultureInfo
ci = New CultureInfo("en-CA")
CultureInfo.DefaultThreadCurrentCulture = ci

which sets the culture code for all threads to English/Canadian.

Posted by Peter Vogel on 05/03/2016 at 10:19 AM


comments powered by Disqus

Featured

  • What's New in TypeScript 5.3

    Microsoft advanced TypeScript to version 5.3 with a bevy of changes affecting everything from import attributes to interactive inlay hints for types, along with multiple optimizations.

  • Finally Go Eyes On with Upcoming Visual Studio 2022 UI Refresh

    Six months ago, Microsoft teased Visual Studio 2022 developers by announcing an upcoming UI refresh, which they can now finally get their eyes on in the new v17.9 preview 1.

  • DBSCAN Data Clustering from Scratch Using C#

    Compared to other clustering techniques, DBSCAN does not require you to explicitly specify how many data clusters to use, explains Dr. James McCaffrey of Microsoft Research in this full-code, step-by-step machine language tutorial.

  • GitHub Copilot Leads Productivity Gains in New Visual Studio 2022 17.8

    In announcing Visual Studio 2022 17.8 today, Microsoft emphasized community-driven productivity gains among the new features and functionality.

  • Microsoft Ships .NET 8

    In announcing .NET 8 today, Microsoft emphasized the cloud, performance, full-stack Blazor, AI and .NET MAUI as major highlights of the latest edition of the company's free, cross-platform, open source developer platform.

Subscribe on YouTube

Upcoming Events