< Day Day Up > |
11.1 Determining a User 's Culture Information
TechniqueYou use the CultureInfo class to retrieve and set the currently executing thread's culture information. The static method CurrentCulture defined within the CultureInfo class creates a CultureInfo object that you can use to retrieve various cultural properties. Some of these properties include the locale Id ( LCID ), calendars used in that culture, International Organization for Standardization (ISO) identifiers, and the name of the culture as displayed in the language of that culture. Figure 11.1 shows the CultureInfo Browser application created as a supplement for this recipe. The property grid within the application contains the various CultureInfo properties for the Farsi culture. Figure 11.1. The CultureInfo class is the primary class used to retrieve information about a user's current culture settings.
CommentsThe CultureInfo class is the first stepping stone into the globalization realm. Whenever your application executes, the Windows API function GetUserDefaultLCID retrieves the locale identifier for the current user. This identifier is then used to create the CultureInfo object that you can retrieve with a call to the static CurrentCulture method. You are then free to access the various properties within this CultureInfo object to effectively display correct information for that culture. Some of the properties that you will most likely access include the NumberFormatInfo object used to correctly display culturally aware numbers and the DateTimeFormat object used for the correct date and time display or manipulation. Recipes later in this chapter demonstrate how to use these objects. |
< Day Day Up > |