Click here to Skip to main content
11,927,422 members (45,549 online)
Click here to Skip to main content
Add your own
alternative version


7 bookmarked

Globalization in C# .NET Assemblies

, 13 Jul 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
Explains the .NET approach towards globalization, and introduces the tools and methods to successfully implement globalization.


C# .NET assemblies are often built and deployed globally. The current business model of outsourcing development overseas results in global customers. The Developer implementing the outsourced solution must take local languages and customs into account. There are different ways of expressing characters, dates, times, currencies and floating point numbers in different cultures. In this article, Anupam Banerji explains the .NET approach towards globalization, and introduces the tools and methods to successfully implement globalization.


The software development business model today often results in the separation of the design and actual implementation in two separate countries. This will result in cultural differences. Dates and characters in Japan are expressed differently to those in the U.A.E. or Australia. A database in Spain holds currency information differently to that in the U.S. The Developer must be able to implement a foreign design that delivers the results expected overseas.

The .NET Framework provides us with objects to handle globalization issues. There are also several ways to compare and sort different cultural formats. Converting a Gregorian date to a Hijri date is a matter of a single call.

Culture & Locale Settings

There are two ways to set the culture in the .NET Framework. Both properties belong to the System.Threading namespace. They are Thread.CurrentThread.CurrentCulture and the Thread.CurrentThread. CurrentUICulture. The CurrentCulture property is set to calculate values of variables in a specific cultural format. The CurrentUICulture property determines the actual format that the value is displayed in.

To set the properties, we create an instance of the CultureInfo object.

using System.Globalization; 
CultureInfo ci = new CultureInfo("en-US"); 

The string “en-US” tells the .NET runtime that the neutral culture is in English and that the locale, or region is the United States. The CultureInfo instance has a number of read only properties, which are used by the Developer to determine specific cultural settings.

Custom Cultures

A custom culture can be created by creating an instance of the CultureAndRegionInfo Builder property. The Register() method of this object instance should be called to save the culture to the registry. The example below shows a new culture created out of an existing culture:

CultureAndRegionInfoBuilder cb = new CultureAndRegionInfoBuilder("fr-AB", CultureAndRegionModifiers.None); 
cb.LoadDataFromCultureInfo(new CultureInfo ("fr-FR")); 
cb.LoadDataFromRegionInfo(new RegionInfo ("FR")); 

This creates a new culture “fr-AB”, copying the cultural settings from French in France. To register the new culture, the assembly must be executed with administrative rights.

Sorting and Comparing Strings

String sorting is a key difference between cultures. Characters are treated differently in the sort order and cultures often support more than one sort order. For example, the German in Germany culture has two sort orders; one is the dictionary sort order and the other is the phonebook sort order. Hungarian has the default and technical sort orders, and Georgian has the traditional and the modern sort orders! The design should specify sort order requirements before being approved.

To use an alternate sort order, create an instance of the CultureInfo class with the locale identifier (LCID) in hexadecimal. The Hungarian technical sort LCID is 0x0001040e. Therefore, the CultureInfo instance is created as:

CultureInfo ci = new CultureInfo (0x0001040e); 

One would then assign the instanced object to the CurrentCulture property. Sorting methods in .NET (for example, in a collection object) can then be used. The data will be sorted in the LCID format of the CultureInfo.LCID property.

Comparing Two Cultures

To compare values between two cultures, one has to ensure that any comparison is performed in either one or the other. There is also a comparison that may be performed in an invariant culture. To perform culture invariant comparisons, set the CurrentCulture property to CultureInfo.InvariantCulture.

A Quick Example: Culture Invariant Sort

We have a list of random strings that we wish to sort. The text file is in Norway. The strings are:


The sorted strings in the Norwegian culture (“nn-NO”) are:


The positions of the ü and ä characters are after the z character. The culture invariant strings are:


The culture invariant sort should be used when the sort results are compared to other cultures, for example, against Czech, French, Danish, Spanish or English.

Globalization allows the .NET Developer to sort, process and display data types in culture and locale specific formats. A good .NET design will incorporate globalization, especially if the product is outsourced to a foreign culture or locale. A globalization incorporated product will ensure that the end user is satisfied with the display, and that the product functions as required.

A PDF version of this technical article may be downloaded from the Coactum Solutions website at


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Anupam Banerji
Australia Australia
Anupam Banerji has a wealth of experience writing, evaluating and validating systems for the cement, pharmaceuticals, energy derivatives and banking and finance industries.

Additionally, he’s designed and written software solutions in VB/VBA, SQL and C# .NET, and has worked as a Quantitative Analyst in banking. He is a Microsoft Certified Technology Specialist in WPF 3.5 and has written and deployed commercial solutions in the .NET 3.5 and 4.0 object models. He has also written applications in MVVM and Prism.

You may also be interested in...

Comments and Discussions

Questiongood Pin
Hua Yujun31-Mar-13 18:21
memberHua Yujun31-Mar-13 18:21 
Question[My vote of 1] not good Pin
CIDev6-Sep-12 4:55
memberCIDev6-Sep-12 4:55 
SuggestionLook at MSDN Globalizing and Localizing Applications Pin
George Mamaladze5-Aug-11 0:02
memberGeorge Mamaladze5-Aug-11 0:02 
GeneralMy vote of 1 Pin
MicroImaging14-Jul-10 7:13
memberMicroImaging14-Jul-10 7:13 
GeneralMy vote of 4 Pin
Lisa Boden14-Jul-10 4:40
memberLisa Boden14-Jul-10 4:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.151126.1 | Last Updated 14 Jul 2010
Article Copyright 2010 by Anupam Banerji
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid