CultureAndRegionInfoBuilder Constructor

Note: This constructor is new in the .NET Framework version 2.0.

Initializes a new instance of the CultureAndRegionInfoBuilder class.

Namespace: System.Globalization
Assembly: sysglobl (in sysglobl.dll)

public CultureAndRegionInfoBuilder (
	string cultureName,
	CultureAndRegionModifiers flags
)
public CultureAndRegionInfoBuilder (
	String cultureName, 
	CultureAndRegionModifiers flags
)
public function CultureAndRegionInfoBuilder (
	cultureName : String, 
	flags : CultureAndRegionModifiers
)

Parameters

cultureName

The name of a culture.

flags

One of the CultureAndRegionModifiers values that specifies whether the new CultureAndRegionInfoBuilder object is a neutral culture, replaces an existing culture and region, or is a new culture.

Exception typeCondition

ArgumentNullException

cultureName is a null reference (Nothing in Visual Basic).

ArgumentException

cultureName is the empty string ("").

-or-

cultureName contains characters other than '0' through '9', 'a' through 'z', 'A' through 'Z', hyphen (-), or underscore (_).

-or-

cultureName contains hyphens (-) to delimit components, but one or more of the prefix, language, region, or suffix components is absent. That is, two or more hyphens are adjacent.

-or-

cultureName is longer than 84 characters.

-or-

cultureName contains hyphens to delimit components, but one or more of the components is longer than 8 characters.

-or-

cultureName contains a leading or trailing hyphen (-) or underscore (_).

-or-

cultureName specifies an alternate sort replacement culture instead of a .NET Framework culture. For example, culturenName is "de-de_phoneb", a culture that sorts strings as they appear in a German telephone book, instead of "de-DE", the German-Germany culture.

-or-

flags contains an invalid combination of CultureAndRegionModifiers values.

-or-

flags contains Replacement or Neutral and cultureName specifies a culture that is not found.

-or-

flags contains Replacement and cultureName specifies a user-created custom culture that does not replace a culture shipped with the .NET Framework.

-or-

flags contains Neutral and cultureName specifies a culture that is not a neutral culture.

-or-

flags contains Neutral and cultureName specifies a user-created custom culture that replaces a specific culture shipped with the .NET Framework.

The cultureName parameter specifies the name of the new CultureAndRegionInfoBuilder object.

The flags parameter is a CultureAndRegionModifiers value that specifies whether the new CultureAndRegionInfoBuilder object is a new custom culture, or replaces an existing neutral culture, specific culture, or Windows locale.

If the cultureName parameter specifies an existing .NET Framework culture, registered custom culture, or culture generated from a Windows locale, the CultureAndRegionInfoBuilder constructor automatically populates the new CultureAndRegionInfoBuilder object with culture and region information.

Populate the new CultureAndRegionInfoBuilder object with culture and region information by invoking the LoadDataFromCultureInfo and LoadDataFromRegionInfo methods.

Custom Culture Names

The preferred format of the cultureName parameter for a new, custom culture is "[prefix-]language[-region][-suffix[]]", where the language component is required and the prefix, region, and suffix components are optional. The maximum length of each component is 8 characters and the maximum length of the entire cultureName parameter is 84 characters.

The prefix component is the Internet Assigned Numbers Authority (IANA) identification. Specify "i-" or "I-" for culture names registered with the IANA, or "x-" or "X-" for culture names reserved for private use; otherwise, prefix is not required. For more information, see RFC 3066, "Tags for the Identification of Languages," at http://go.microsoft.com/fwlink/?linkid=45286.

The language component of the cultureName parameter specifies a lowercase two-letter code derived from ISO 639-1, and region specifies an uppercase two-letter code derived from ISO 3166. For example, "en-US" stands for English as spoken in the United States. The absence of the region component signifies a neutral culture.

A cultureName that is the same as the name of a culture included with the .NET Framework signifies a replacement (override) culture. The values that can be assigned to the properties of a replacement culture are limited. For more information about such limitations, see the exceptions for each property.

Use the suffix component to distinguish similar cultures. For example, two companies, ABC and XYZ, create and share a new ASP.NET Web service to promote their products in different markets around the world. The Web pages for the service display information such as the regional logo and local telephone number of each company depending on the user's culture. The culture-specific content for each Web page is in separate resource files identified by culture name and qualified by company name. For example, resource files for the en-US and ja-JP cultures are named en-US-ABC, en-US-XYZ, ja-JP-ABC, and ja-JP-XYZ. The "ABC" and "XYZ" suffixes enable the Web service to use the same application logic to display different market-specific information.

The suffix component can itself consist of subcomponents, where each subcomponent is delimited by a hyphen and the maximum length of each subcomponent is 8 characters. For example, if "en-US-honda-cars" is the cultureName parameter, "-honda-cars" is the suffix component.

The following code example creates a custom culture with a private use prefix, then lists a set of its properties. The first property lists the name of the culture.

// This example demonstrates a System.Globalization.Culture-
// AndRegionInfoBuilder constructor and some of the properties 
// of the CultureAndRegionInfoBuilder object that is created.
// Compile this example with a reference to sysglobl.dll.

using System;
using System.Globalization;

class Sample 
{
    public static void Main() 
    {

// Construct a new, privately used culture that extends the en-US culture 
// provided by the .NET Framework. In this sample, the CultureAndRegion-
// Types.Specific parameter creates a minimal CultureAndRegionInfoBuilder 
// object that you must populate with culture and region information.

    CultureAndRegionInfoBuilder cib = null;
    try {
        cib = new CultureAndRegionInfoBuilder(
                                          "x-en-US-sample",
                                          CultureAndRegionModifiers.None);
        }
    catch (ArgumentException ae)
        {
        Console.WriteLine(ae);
        return;
        }

// Populate the new CultureAndRegionInfoBuilder object with culture information.

    CultureInfo ci = new CultureInfo("en-US");
    cib.LoadDataFromCultureInfo(ci);

// Populate the new CultureAndRegionInfoBuilder object with region information.

    RegionInfo  ri = new RegionInfo("US");
    cib.LoadDataFromRegionInfo(ri);

// Display some of the properties for the x-en-US-sample custom culture.

    Console.Clear();
    Console.WriteLine("CultureName:. . . . . . . . . . {0}", cib.CultureName);
    Console.WriteLine("CultureEnglishName: . . . . . . {0}", cib.CultureEnglishName);
    Console.WriteLine("CultureNativeName:. . . . . . . {0}", cib.CultureNativeName);
    Console.WriteLine("GeoId:. . . . . . . . . . . . . {0}", cib.GeoId);
    Console.WriteLine("IsMetric: . . . . . . . . . . . {0}", cib.IsMetric);
    Console.WriteLine("ISOCurrencySymbol:. . . . . . . {0}", cib.ISOCurrencySymbol);
    Console.WriteLine("RegionEnglishName:. . . . . . . {0}", cib.RegionEnglishName);
    Console.WriteLine("RegionName: . . . . . . . . . . {0}", cib.RegionName);
    Console.WriteLine("RegionNativeName: . . . . . . . {0}", cib.RegionNativeName);
    Console.WriteLine("ThreeLetterISOLanguageName: . . {0}", cib.ThreeLetterISOLanguageName);
    Console.WriteLine("ThreeLetterISORegionName: . . . {0}", cib.ThreeLetterISORegionName);
    Console.WriteLine("ThreeLetterWindowsLanguageName: {0}", cib.ThreeLetterWindowsLanguageName);
    Console.WriteLine("ThreeLetterWindowsRegionName: . {0}", cib.ThreeLetterWindowsRegionName);
    Console.WriteLine("TwoLetterISOLanguageName: . . . {0}", cib.TwoLetterISOLanguageName);
    Console.WriteLine("TwoLetterISORegionName: . . . . {0}", cib.TwoLetterISORegionName);
    }
}
/*
This code example produces the following results:

CultureName:. . . . . . . . . . x-en-US-sample
CultureEnglishName: . . . . . . English
CultureNativeName:. . . . . . . English
GeoId:. . . . . . . . . . . . . 244
IsMetric: . . . . . . . . . . . False
ISOCurrencySymbol:. . . . . . . USD
RegionEnglishName:. . . . . . . United States
RegionName: . . . . . . . . . . US
RegionNativeName: . . . . . . . United States
ThreeLetterISOLanguageName: . . eng
ThreeLetterISORegionName: . . . USA
ThreeLetterWindowsLanguageName: ENU
ThreeLetterWindowsRegionName: . USA
TwoLetterISOLanguageName: . . . en
TwoLetterISORegionName: . . . . US

*/

  • Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see .

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show: