CultureAndRegionInfoBuilder(String, CultureAndRegionModifiers) Constructor

Definition

Initializes a new instance of the CultureAndRegionInfoBuilder class.

C#
public CultureAndRegionInfoBuilder(string cultureName, System.Globalization.CultureAndRegionModifiers flags);

Parameters

cultureName
String

The name of a culture.

flags
CultureAndRegionModifiers

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

Exceptions

cultureName is null.

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, cultureName 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.

Examples

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.

C#
// 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

*/

Remarks

For more information about this API, see Supplemental API remarks for System.Globalization.CultureAndRegionInfoBuilder constructor.

Applies to

Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

See also