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


C# TimeSpan.GetHashCode方法代码示例

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


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

示例1: PosTest1

    public bool PosTest1()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest1: GetHashCode should always return the same value for same TimeSpan instance");

        try
        {
            long randValue = TestLibrary.Generator.GetInt64(-55);
            TimeSpan ts = new TimeSpan(randValue);

            int hash1 = ts.GetHashCode();
            int hash2 = ts.GetHashCode();

            if (hash1 != hash2)
            {
                TestLibrary.TestFramework.LogError("001.1", "GetHashCode not always return the same value for same TimeSpan instance");
                TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLE] hash1 = " + hash1 + ", hash2 = " + hash2 + ", randValue = " + randValue);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("001.0", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return retVal;
    }
开发者ID:l1183479157,项目名称:coreclr,代码行数:30,代码来源:timespangethashcode.cs

示例2: runTest

 public virtual bool runTest()
   {
   int iCountErrors = 0;
   int iCountTestcases = 0;
   Console.Error.WriteLine( strName + ": " + strTest + " runTest started..." );
   TimeSpan	ts1;
   TimeSpan	ts2;
   TimeSpan	tsResult;
   do
     {
     ++iCountTestcases;
     Console.Error.WriteLine( "[]  Negate positive time to yield negative time" );
     try
       {
       ts1 = new TimeSpan(10*TimeSpan.TicksPerHour);
       ts2 = new TimeSpan(10*TimeSpan.TicksPerHour);
       if ( ts1.GetHashCode() != ts2.GetHashCode() )
	 {
	 String strInfo = strTest + " error: ";
	 strInfo = strInfo + "Expected Ticks <" + ts1.GetHashCode() + "> ";
	 strInfo = strInfo + "Returned Ticks <" + ts2.GetHashCode() + "> ";
	 Console.WriteLine( strTest+ "E_101a: " + strInfo );
	 ++iCountErrors;
	 break;
	 }
       }
     catch (Exception ex)
       {
       Console.WriteLine( strTest+ "E_10001: Unexpected Exception: " + ex.ToString() );
       ++iCountErrors;
       break;
       }
     }
   while ( false );
   Console.Error.Write( strName );
   Console.Error.Write( ": " );
   if ( iCountErrors == 0 )
     {
     Console.Error.WriteLine( strTest + " iCountTestcases==" + iCountTestcases + " paSs" );
     return true;
     }
   else
     {
     System.String strFailMsg = null;
     Console.WriteLine( strTest+ strPath );
     Console.WriteLine( strTest+ "FAiL" );
     Console.Error.WriteLine( strTest + " iCountErrors==" + iCountErrors );
     return false;
     }
   }
开发者ID:ArildF,项目名称:masters,代码行数:50,代码来源:co2926gethashcode.cs

示例3: TestEquals

    public static void TestEquals(TimeSpan timeSpan1, object obj, bool expected)
    {
        if (obj is TimeSpan)
        {
            TimeSpan timeSpan2 = (TimeSpan)obj;
            Assert.Equal(expected, TimeSpan.Equals(timeSpan1, timeSpan2));
            Assert.Equal(expected, timeSpan1.Equals(timeSpan2));
            Assert.Equal(expected, timeSpan1 == timeSpan2);
            Assert.Equal(!expected, timeSpan1 != timeSpan2);

            Assert.Equal(expected, timeSpan1.GetHashCode().Equals(timeSpan2.GetHashCode()));
        }
        Assert.Equal(expected, timeSpan1.Equals(obj));
    }
开发者ID:eerhardt,项目名称:corefx,代码行数:14,代码来源:TimeSpan.cs

示例4: GetHashCode_Test5

		public MFTestResults GetHashCode_Test5(  )
		{
            /// <summary>
            /// 1. Test that GetHashCode returns the same for the same TimeSpan
            /// 2. Test that GetHashCode returns differently for different TimeSpans
            /// </summary>
            ///
            Log.Comment("Testing the GetHashCode method");
			bool testResult = true;
            Random random = new Random();
            Log.Comment("Test that GetHashCode returns the same for the same TimeSpan");
			for( int i = 0; i<30; i++ )
			{
				int hours = random.Next(23);
				int minutes = random.Next(59);
				int seconds = random.Next(59);
				TimeSpan ts01 = new TimeSpan( hours, minutes, seconds );
				TimeSpan ts02 = new TimeSpan( hours, minutes, seconds );
				Log.Comment( ts01.GetHashCode().ToString() + " == " + 
                    ts02.GetHashCode().ToString() );
				testResult &= (ts01.GetHashCode() == ts02.GetHashCode());
			}

			TimeSpan ts1 = new TimeSpan( 1,1,1 );
            Log.Comment("Test that GetHashCode returns differently for different TimeSpans");
            Log.Comment("This may fail erroneously.");  
            Log.Comment("From the docs two different TimeSpans may have same hashcode" );
			Log.Comment( "But, for the most part the values should be different." );
			for( int i = 0; i < 5; i++ )
			{
				TimeSpan ts2 = new TimeSpan( random.Next(23),
                    random.Next(59),random.Next(59) );
				Log.Comment( ts1.GetHashCode().ToString() + " Does Not Equal " + 
                    ts2.GetHashCode().ToString() );
				if( ts1 != ts2 )
					testResult &= (ts1.GetHashCode() != ts2.GetHashCode());
				else
					testResult &= (ts1.GetHashCode() == ts2.GetHashCode());
			}

			return (testResult? MFTestResults.Pass: MFTestResults.Fail);
		}
开发者ID:aura1213,项目名称:netmf-interpreter,代码行数:42,代码来源:SystemTimeSpanTests.cs


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