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


C# Int32.GetHashCode方法代码示例

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


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

示例1: Print

        public void Print()
        {
            System.Int32 i = new System.Int32();
            i = 23;
            Console.WriteLine(i.GetHashCode());
            Console.WriteLine(i.GetType());
            Console.WriteLine(i.GetTypeCode());
            Console.WriteLine(i.ToString());
            if (i.CompareTo(20) < 0)
                Console.WriteLine("{0} < 20", i);
            else if (i.CompareTo(20) == 0)
                Console.WriteLine("i equals 20");
            else
                Console.WriteLine("i > 20");
            Console.WriteLine(System.Int32.MinValue);
            Console.WriteLine(System.Int32.MaxValue);
            Console.WriteLine(System.Double.Epsilon);
            Console.WriteLine(System.Double.PositiveInfinity);
            Console.WriteLine(System.Double.NegativeInfinity);
            Console.WriteLine(System.Boolean.FalseString);
            Console.WriteLine(System.Boolean.TrueString);

            Console.WriteLine(System.Char.IsDigit('1'));
            Console.WriteLine(System.Char.IsLetter('9'));
            Console.WriteLine(System.Char.IsWhiteSpace("naynish chaughule", 7));
            Console.WriteLine(System.Char.IsPunctuation('?'));

            //parsing
            double d = System.Double.Parse("90.35");
            Console.WriteLine(d);
            System.Int64 longVar = Convert.ToInt64("43654703826562");
            Console.WriteLine(longVar);

            Console.WriteLine(System.Guid.NewGuid());
            System.DateTime dt = new DateTime(2012, 6, 04);
            Console.WriteLine(dt.ToLongDateString());
            Console.WriteLine(DateTime.Now.ToLongTimeString());
            Console.WriteLine(dt.DayOfWeek);
            Console.WriteLine(dt.AddMonths(5).ToLongDateString());
            Console.WriteLine("{0} {1} {2}", dt.Date, dt.DayOfYear, dt.IsDaylightSavingTime());

            TimeSpan ts = new TimeSpan(24, 30, 30);
            Console.WriteLine(dt.Add(ts).ToLongDateString());
            Console.WriteLine(ts.Subtract(new TimeSpan(2,30, 45)));
            NumericsDemo();
            WorkingWithStrings();
        }
开发者ID:naynishchaughule,项目名称:CSharp,代码行数:47,代码来源:Hierarchy.cs

示例2: runTest

 public bool runTest()
   {
   Console.Error.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
   int iCountErrors = 0;
   int iCountTestcases = 0;
   String strLoc = "Loc_000oo";
   short[] in2Arr = new Int16[10];
   int[] in4Arr = new Int32[5];
   Boolean[] boArr = new Boolean[3];
   int iHashCode1, iHashCode2;
   try {
   do
     {
     strLoc = "Loc_01hc";
     iCountTestcases++;
     in2Arr = new Int16[10];
     iHashCode1 = in2Arr.GetHashCode();
     iHashCode2 = in2Arr.GetHashCode();
     if(iHashCode1 != iHashCode2)
       {
       iCountErrors++;
       Console.WriteLine( s_strTFAbbrev+ ", Err_01hc! , Array.GetHashCode on a same instance twice result different value." );
       }
     strLoc = "Loc_02hc";
     iCountTestcases++;
     in4Arr = new Int32[5];
     iHashCode1 = in2Arr.GetHashCode();
     iHashCode2 = in4Arr.GetHashCode();
     if(iHashCode1 == iHashCode2)
       {
       iCountErrors++;
       Console.WriteLine( s_strTFAbbrev+ ", Err_02hc! , Array.GetHashCode on a different array type instances result same value." );
       }
     boArr = new Boolean[3];
     strLoc = "Loc_03hc";
     iCountTestcases++;
     iHashCode1 = in2Arr.GetHashCode();
     iHashCode2 = boArr.GetHashCode();
     if(iHashCode1 == iHashCode2)
       {
       iCountErrors++;
       Console.WriteLine( s_strTFAbbrev+ ", Err_03hc! , Array.GetHashCode on a different array type instances result same value." );
       }
     strLoc = "Loc_04hc";
     iCountTestcases++;
     Array Arr1 = Array.CreateInstance(typeof(double), 10);
     Array Arr2 = Array.CreateInstance(typeof(Single), 0);
     iHashCode1 = Arr1.GetHashCode();
     iHashCode2 = Arr2.GetHashCode();
     if( iHashCode1 == iHashCode2 )
       {
       iCountErrors++;
       Console.WriteLine( s_strTFAbbrev+ ", Err_04hc! , Array.GetHashCode on a different array type instances result same value." );
       }
     int[][] i4Arr = new int[3][];
     i4Arr[0] = new int[] {1, 2, 3};
     i4Arr[1] = new int[] {1, 2, 3, 4, 5, 6};
     i4Arr[2] = new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9};
     strLoc = "Loc_05hc";
     iCountTestcases++;
     iHashCode1 = i4Arr.GetHashCode();
     iHashCode2 = i4Arr.GetHashCode();
     if( iHashCode1 != iHashCode2 )
       {
       iCountErrors++;
       Console.WriteLine( s_strTFAbbrev+ ", Err_05hc! , Array.GetHashCode on a same instance of jagged array should result same value." );
       }
     strLoc = "Loc_06hc";
     iCountTestcases++;
     string[,,,,,] strArr = new string[6,5,4,3,2,1];
     iHashCode2 = strArr.GetHashCode();
     if( iHashCode1 == iHashCode2 )
       {
       iCountErrors++;
       Console.WriteLine( s_strTFAbbrev+ ", Err_06hc! , Array.GetHashCode on a different array type instances result same value." );
       }
     } while (false);
   } catch (Exception exc_general ) {
   ++iCountErrors;
   Console.WriteLine(s_strTFAbbrev +", Error Err_8888yyy!  strLoc=="+ strLoc +", exc_general=="+exc_general);
   }
   if ( iCountErrors == 0 )
     {
     Console.Error.WriteLine( "paSs.   "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases);
     return true;
     }
   else
     {
     Console.Error.WriteLine("FAiL!   "+s_strTFPath+" "+s_strTFName+" ,inCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums );
     return false;
     }
   }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:92,代码来源:co6001gethashcode.cs


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