当前位置: 首页>>代码示例>>C#>>正文


C# RegionInfo构造函数代码示例

本文整理汇总了C#中System.Globalization.RegionInfo.RegionInfo构造函数的典型用法代码示例。如果您正苦于以下问题:C# RegionInfo构造函数的具体用法?C# RegionInfo怎么用?C# RegionInfo使用的例子?那么恭喜您, 这里精选的构造函数代码示例或许可以为您提供帮助。您也可以进一步了解该构造函数所在System.Globalization.RegionInfo的用法示例。


在下文中一共展示了RegionInfo构造函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

//引入命名空间
using System;
using System.Globalization;

public class SamplesRegionInfo  {

   public static void Main()  {

      // Creates a RegionInfo using the ISO 3166 two-letter code.
      RegionInfo myRI1 = new RegionInfo( "US" );

      // Creates a RegionInfo using a CultureInfo.LCID.
      RegionInfo myRI2 = new RegionInfo( new CultureInfo("en-US",false).LCID );

      // Compares the two instances.
      if ( myRI1.Equals( myRI2 ) )
         Console.WriteLine( "The two RegionInfo instances are equal." );
      else
         Console.WriteLine( "The two RegionInfo instances are NOT equal." );
   }
}
开发者ID:.NET开发者,项目名称:System.Globalization,代码行数:21,代码来源:RegionInfo

输出:

The two RegionInfo instances are equal.

示例2: Main

//引入命名空间
using System;
using System.Globalization;

public class SamplesRegionInfo  {

   public static void Main()  {

      // Creates an array containing culture names.
      String[] myCultures = new String[]  { "", "ar", "ar-DZ", "en", "en-US" };

      // Creates a RegionInfo for each of the culture names.
      //    Note that "ar" is the culture name for the neutral culture "Arabic",
      //    but it is also the region name for the country/region "Argentina";
      //    therefore, it does not fail as expected.
      Console.WriteLine("Without checks...");
      foreach (String culture in myCultures)  {
         try  {
            RegionInfo myRI = new RegionInfo( culture );
         }
         catch ( ArgumentException e )  {
            Console.WriteLine( e.ToString() );
         }
      }

      Console.WriteLine();

      Console.WriteLine( "Checking the culture names first..." );
      foreach (String culture in myCultures)  {
         if ( culture == "" )  {
            Console.WriteLine("The culture is the invariant culture.");
         }
         else  {
            CultureInfo myCI = new CultureInfo( culture, false );
            if ( myCI.IsNeutralCulture )
                {
                    Console.WriteLine( "The culture {0} is a neutral culture.", culture );
                }
                else   {
               Console.WriteLine( "The culture {0} is a specific culture.", culture );
               try  {
                  RegionInfo myRI = new RegionInfo( culture );
               }
               catch ( ArgumentException e )  {
                  Console.WriteLine( e.ToString() );
               }
            }
         }
      }
   }
}
开发者ID:.NET开发者,项目名称:System.Globalization,代码行数:51,代码来源:RegionInfo

输出:

Without checks...
System.ArgumentException: Region name '' is not supported.
Parameter name: name
   at System.Globalization.RegionInfo..ctor(String name)
   at SamplesRegionInfo.Main()
System.ArgumentException: Region name 'en' is not supported.
Parameter name: name
   at System.Globalization.CultureTableRecord..ctor(String regionName, Boolean useUserOverride)
   at System.Globalization.RegionInfo..ctor(String name)
   at SamplesRegionInfo.Main()

Checking the culture names first...
The culture is the invariant culture.
The culture ar is a neutral culture.
The culture ar-DZ is a specific culture.
The culture en is a neutral culture.
The culture en-US is a specific culture.


注:本文中的System.Globalization.RegionInfo.RegionInfo构造函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。