CultureAndRegionInfoBuilder(String, CultureAndRegionModifiers) CultureAndRegionInfoBuilder(String, CultureAndRegionModifiers) CultureAndRegionInfoBuilder(String, CultureAndRegionModifiers) CultureAndRegionInfoBuilder(String, CultureAndRegionModifiers) Constructor

定义

初始化 CultureAndRegionInfoBuilder 类的新实例。Initializes a new instance of the CultureAndRegionInfoBuilder class.

public:
 CultureAndRegionInfoBuilder(System::String ^ cultureName, System::Globalization::CultureAndRegionModifiers flags);
public CultureAndRegionInfoBuilder (string cultureName, System.Globalization.CultureAndRegionModifiers flags);
new System.Globalization.CultureAndRegionInfoBuilder : string * System.Globalization.CultureAndRegionModifiers -> System.Globalization.CultureAndRegionInfoBuilder
Public Sub New (cultureName As String, flags As CultureAndRegionModifiers)

参数

cultureName
String String String String

区域性的名称。The name of a culture.

flags
CultureAndRegionModifiers CultureAndRegionModifiers CultureAndRegionModifiers CultureAndRegionModifiers

一个 CultureAndRegionModifiers 值,指定新的 CultureAndRegionInfoBuilder 对象是非特定区域性、新区域性,还是要替换现有的区域性和国家/地区。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.

异常

cultureName 为空字符串 ("")。cultureName is the empty string ("").

-or- cultureName 包含除“0”到“9”、“a”到“z”、“A”到“Z”、连字符 (-) 或下划线 () 以外的字符。cultureName contains characters other than "0" through "9", "a" through "z", "A" through "Z", hyphen (-), or underscore ().

-or- cultureName 包含用于分隔各个部分的连字符 (-),但是缺少 prefixlanguageregionsuffix 这些部分中的一个或多个。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 的长度超过 84 个字符。cultureName is longer than 84 characters.

- 或 --or- cultureName 包含用于分隔各个部分的连字符,但是有一个或多个部分的长度超过 8 个字符。cultureName contains hyphens to delimit components, but one or more of the components is longer than 8 characters.

-or- cultureName 包含前导或末尾连字符 (-) 或下划线 ()。cultureName contains a leading or trailing hyphen (-) or underscore ().

-or- cultureName 指定其他排序替换区域性而不是 .NET Framework 区域性。cultureName specifies an alternate sort replacement culture instead of a .NET Framework culture. 例如,culturenName 是“de-de_phoneb”(按照德语电话簿中的显示顺序对字符串排序的区域性)而不是德语(德国)区域性“de-DE”。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 包含无效的 CultureAndRegionModifiers 值组合。flags contains an invalid combination of CultureAndRegionModifiers values.

-or- flags 包含 ReplacementNeutral,而且没有找到 cultureName 指定的区域性。flags contains Replacement or Neutral and cultureName specifies a culture that is not found.

-or- flags 包含 Replacement,而 cultureName 指定的由用户创建的自定义区域性没有替换 .NET Framework 附带的区域性。flags contains Replacement and cultureName specifies a user-created custom culture that does not replace a culture shipped with the .NET Framework.

-or- flags 包含 Neutral,而 cultureName 指定的区域性不是非特定区域性。flags contains Neutral and cultureName specifies a culture that is not a neutral culture.

-or- flags 包含 Neutral,而 cultureName 指定的由用户创建的自定义区域性替换了 .NET Framework 附带的特定区域性。flags contains Neutral and cultureName specifies a user-created custom culture that replaces a specific culture shipped with the .NET Framework.

示例

下面的代码示例创建一个具有私有使用前缀的自定义区域性, 并列出它的一组属性。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 a custom culture object created with the constructor.

#using <sysglobl.dll>

using namespace System;
using namespace System::Globalization;

int main()
{
    CultureAndRegionInfoBuilder^ builder = 
        gcnew CultureAndRegionInfoBuilder
        ("x-en-US-sample", CultureAndRegionModifiers::None);
    
    // Display some of the properties 
    // for the en-US culture.
    Console::WriteLine("CultureName:. . . . . . . . . . {0}", 
        builder->CultureName);
    Console::WriteLine("CultureEnglishName: . . . . . . {0}", 
        builder->CultureEnglishName);
    Console::WriteLine("CultureNativeName:. . . . . . . {0}", 
        builder->CultureNativeName);
    Console::WriteLine("GeoId:. . . . . . . . . . . . . {0}", 
        builder->GeoId);
    Console::WriteLine("IsMetric: . . . . . . . . . . . {0}", 
        builder->IsMetric);
    Console::WriteLine("ISOCurrencySymbol:. . . . . . . {0}", 
        builder->ISOCurrencySymbol);
    Console::WriteLine("RegionEnglishName:. . . . . . . {0}", 
        builder->RegionEnglishName);
    Console::WriteLine("RegionName: . . . . . . . . . . {0}", 
        builder->RegionName);
    Console::WriteLine("RegionNativeName: . . . . . . . {0}", 
        builder->RegionNativeName);
    Console::WriteLine("ThreeLetterISOLanguageName: . . {0}", 
        builder->ThreeLetterISOLanguageName);
    Console::WriteLine("ThreeLetterISORegionName: . . . {0}", 
        builder->ThreeLetterISORegionName);
    Console::WriteLine("ThreeLetterWindowsLanguageName: {0}", 
        builder->ThreeLetterWindowsLanguageName);
    Console::WriteLine("ThreeLetterWindowsRegionName: . {0}", 
        builder->ThreeLetterWindowsRegionName);
    Console::WriteLine("TwoLetterISOLanguageName: . . . {0}", 
        builder->TwoLetterISOLanguageName);
    Console::WriteLine("TwoLetterISORegionName: . . . . {0}", 
        builder->TwoLetterISORegionName);
}

/*
This code example produces the following results:

CultureName:. . . . . . . . . . en-US
CultureEnglishName: . . . . . . English (United States)
CultureNativeName:. . . . . . . English (United States)
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

*/
// 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

*/
' 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.

Imports System.Globalization

Class Sample
    Public Shared Sub 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.

        Dim cib As CultureAndRegionInfoBuilder = Nothing
        Try
            cib = New CultureAndRegionInfoBuilder("x-en-US-sample", _
                                                   CultureAndRegionModifiers.None)
        Catch ae As ArgumentException
            Console.WriteLine(ae)
            Return
        End Try
        
        ' Populate the new CultureAndRegionInfoBuilder object with culture information.

        Dim ci As New CultureInfo("en-US")
        cib.LoadDataFromCultureInfo(ci)
        
        ' Populate the new CultureAndRegionInfoBuilder object with region information.

        Dim ri As 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)
    
    End Sub
End Class
'
'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
'

注解

参数指定新CultureAndRegionInfoBuilder的对象的名称。 cultureNameThe cultureName parameter specifies the name of the new CultureAndRegionInfoBuilder object.

参数用于指定新CultureAndRegionInfoBuilder的对象是新的自定义区域性, 还是替换现有的非特定区域性、特定区域性或 Windows 区域设置的值。CultureAndRegionModifiers flagsThe flags parameter is used for 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.

如果参数指定了现有 .NET Framework 区域性、已注册的自定义区域性或从 Windows 区域设置生成的区域性CultureAndRegionInfoBuilder , 则构造函数将CultureAndRegionInfoBuilder使用区域性自动填充新的对象, 并cultureName国家/地区信息。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 country/region information.

通过CultureAndRegionInfoBuilder 调用和LoadDataFromRegionInfo方法, 使用区域性和国家/地区信息填充新的对象。 LoadDataFromCultureInfoPopulate the new CultureAndRegionInfoBuilder object with culture and country/region information by invoking the LoadDataFromCultureInfo and LoadDataFromRegionInfo methods.

自定义区域性名称Custom Culture Names

新的自定义区域性cultureName的参数的首选格式为 "[prefix-]language[-region] [-suffix[]]", 其中, 组件是language必需prefix的,regionsuffix组件是可选的。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. 每个组件的最大长度为8个字符, 整个cultureName参数的最大长度为84个字符。The maximum length of each component is 8 characters and the maximum length of the entire cultureName parameter is 84 characters.

prefix组件是 Internet 号码分配机构 (IANA) 标识。The prefix component is the Internet Assigned Numbers Authority (IANA) identification. 为注册到 IANA 的区域性名称指定 "i-" 或 "I-"; 对于专用用途, 请指定 "x-" 或 "X-"。Specify "i-" or "I-" for culture names registered with the IANA, or "x-" or "X-" for culture names reserved for private use. 否则, 不需要前缀。Otherwise, the prefix is not required. 有关详细信息, 请参阅 RFC 4646 "用于识别语言的标记"。For more information, see RFC 4646, "Tags for the Identification of Languages."

cultureName参数的region组件指定派生自 iso 639-1 的小写双字母代码, 并指定派生自 iso 3166 的由两个字母组成的双字母代码。 languageThe 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. 例如, en-us 代表美国中所说的英语。For example, en-US stands for English as spoken in the United States. 缺少region组件表示非特定区域性。The absence of the region component signifies a neutral culture.

cultureName .NET Framework 中包含的区域性的名称相同的名称表示替换 (重写) 区域性。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.

该应用程序使用suffix该组件来区分类似的文化。The application uses the suffix component to distinguish similar cultures. 例如, 两家公司 (ABC 和 XYZ) 创建并共享新的 ASP.NET Web 服务, 以便在世界各地的不同市场推广其产品。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. 例如, en-us 和 ja-jp 区域性的资源文件命名为 "en-us-ABC, en-us-XYZ, ja-日本-ABC, 和 ja-jp-XYZ"。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. "ABC" 和 "XYZ" 后缀使 Web 服务可以使用相同的应用程序逻辑来显示不同的市场特定信息。The "ABC" and "XYZ" suffixes enable the Web service to use the same application logic to display different market-specific information.

suffix组件可以由子组件组成, 其中每个子组件都由连字符分隔, 每个子组件的最大长度为8个字符。The suffix component can consist of subcomponents, where each subcomponent is delimited by a hyphen and the maximum length of each subcomponent is 8 characters. 例如, 如果 "en-us-honda" 是cultureName参数, 则 "-honda" suffix是组件。For example, if "en-US-honda-cars" is the cultureName parameter, "-honda-cars" is the suffix component.

适用于

另请参阅