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


C# Version.GetHashCode方法代码示例

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


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

示例1: PosTest1

    public bool PosTest1()
    {
        bool retVal = true;
        TestLibrary.TestFramework.BeginScenario("PosTest1: Ensure GetHashCode() successful.");
        Version TestVersion = null;

        try
        {
            for (int i = 0; i < 50; i++)
            {
                int intMajor = TestLibrary.Generator.GetInt32(-55);
                int intMinor = TestLibrary.Generator.GetInt32(-55);
                int intBuild = TestLibrary.Generator.GetInt32(-55);
                int intRevision = TestLibrary.Generator.GetInt32(-55);
                TestVersion = new Version(intMajor, intMinor, intBuild, intRevision);
                int accumulator = 0;
                accumulator |= (TestVersion.Major & 0x0000000F) << 28;
                accumulator |= (TestVersion.Minor & 0x000000FF) << 20;
                accumulator |= (TestVersion.Build & 0x000000FF) << 12;
                accumulator |= (TestVersion.Revision & 0x00000FFF);

                if (TestVersion.GetHashCode() != accumulator)
                {
                    TestLibrary.TestFramework.LogError("P01.1", "GetHashCode() failed!" + TestVersion.ToString());
                    retVal = false;
                    return retVal;
                }
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("P01.2", "Unexpected exception: " + e + TestVersion.ToString());
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

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

示例2: TestGetHashCode

    public void TestGetHashCode()
    {
        var x = new Version(2, 3);
        var y = new Version(2, 3);
        Assert.Equal(x.GetHashCode(), y.GetHashCode());

        x = new Version(2, 3, 4);
        y = new Version(2, 3, 4);
        Assert.Equal(x.GetHashCode(), y.GetHashCode());

        x = new Version(2, 3, 4, 0x000E000F);
        y = new Version(2, 3, 4, 0x000E000F);
        Assert.Equal(x.GetHashCode(), y.GetHashCode());

        x = new Version(5, 5);
        y = new Version(5, 4);
        Assert.NotEqual(x.GetHashCode(), y.GetHashCode());

        x = new Version(10, 10, 10);
        y = new Version(10, 10, 2);
        Assert.NotEqual(x.GetHashCode(), y.GetHashCode());

        x = new Version(10, 10, 10, 10);
        y = new Version(10, 10, 10, 3);
        Assert.NotEqual(x.GetHashCode(), y.GetHashCode());

        x = new Version(10, 10, 10, 10);
        y = new Version(10, 10);
        Assert.NotEqual(x.GetHashCode(), y.GetHashCode());
    }
开发者ID:noahfalk,项目名称:corefx,代码行数:30,代码来源:Version.cs

示例3: HashCode

		public void HashCode ()
		{
			Version v1 = new Version ("1.2.3.4");
			Version v2 = new Version (1, 2, 3, 4);
			Assert.AreEqual (v1.GetHashCode (), v2.GetHashCode (), "HashCode");
		}
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:6,代码来源:VersionTest.cs

示例4: TestEqualsGetHashCode

        public static void TestEqualsGetHashCode(Assert assert)
        {
            assert.Expect(9);

            var v1 = new Version(100, 200, 300, (400 << 16) + 500);
            var v2 = new Version(100, 200, 300, (400 << 16) + 500);
            var v3 = new Version(101, 200, 300, (400 << 16) + 500);
            var o = new object();
            object o2 = v2;

            assert.Ok(v1.Equals(v2), "v1.Equals(v2)");
            assert.NotOk(v1.Equals(v3), "v1.Equals(v3)");
            assert.NotOk(v1.Equals(o), "v1.Equals(o)");
            assert.NotOk(v1.Equals(null), "v1.Equals(null)");
            assert.NotOk(v1.Equals(100), "v1.Equals(100)");
            assert.Ok(v1.Equals(o2), "v1.Equals(o2)");

            assert.Equal(v1.GetHashCode(), 1283637748, "v1.GetHashCode()");
            assert.Equal(v2.GetHashCode(), 1283637748, "v2.GetHashCode()");
            assert.Equal(v3.GetHashCode(), 1552073204, "v3.GetHashCode()");
        }
开发者ID:Cestbienmoi,项目名称:Bridge,代码行数:21,代码来源:TestVersion.cs

示例5: TestEqualsGetHashCode

        public static void TestEqualsGetHashCode()
        {
            var v1 = new Version(100, 200, 300, (400 << 16) + 500);
            var v2 = new Version(100, 200, 300, (400 << 16) + 500);
            var v3 = new Version(101, 200, 300, (400 << 16) + 500);
            var o = new object();
            object o2 = v2;

            Assert.True(v1.Equals(v2), "v1.Equals(v2)");
            Assert.False(v1.Equals(v3), "v1.Equals(v3)");
            Assert.False(v1.Equals(o), "v1.Equals(o)");
            Assert.False(v1.Equals(null), "v1.Equals(null)");
            Assert.False(v1.Equals(100), "v1.Equals(100)");
            Assert.True(v1.Equals(o2), "v1.Equals(o2)");

            Assert.AreEqual(v1.GetHashCode(), 1283637748, "v1.GetHashCode()");
            Assert.AreEqual(v2.GetHashCode(), 1283637748, "v2.GetHashCode()");
            Assert.AreEqual(v3.GetHashCode(), 1552073204, "v3.GetHashCode()");
        }
开发者ID:TinkerWorX,项目名称:Bridge,代码行数:19,代码来源:TestVersion.cs

示例6: Equals

        public static void Equals(Version version1, object obj, bool expected)
        {
            Version version2 = obj as Version;

            Assert.Equal(expected, version1.Equals(version2));
            Assert.Equal(expected, version1.Equals(obj));

            Assert.Equal(expected, version1 == version2);
            Assert.Equal(!expected, version1 != version2);

            if (version2 != null)
            {
                Assert.Equal(expected, version1.GetHashCode().Equals(version2.GetHashCode()));
            }
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:15,代码来源:VersionTests.cs

示例7: CalculateProductId

 /// <summary>
 /// Calculates the product id.
 /// </summary>
 /// <param name="productGuid">The product GUID.</param>
 /// <param name="version">The version.</param>
 /// <returns></returns>
 public static Guid CalculateProductId(Guid productGuid, Version version)
 {
     return WixGuid.HashGuidByInteger(productGuid, version.GetHashCode() + 1);
 }
开发者ID:Eun,项目名称:WixSharp,代码行数:10,代码来源:Project.cs

示例8: runTest

 public bool runTest()
   {
   Console.WriteLine(s_strTFPath + "\\" + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
   String strLoc = "Loc_000oo";
   String strValue = String.Empty;
   int iCountErrors = 0;
   int iCountTestcases = 0;
   try
     {
     Version vTest1 = new Version (5,5);
     Version vTest2 = new Version (5,4);
     strLoc = "Loc_100vy";
     iCountTestcases++;
     if (vTest1.GetHashCode() == vTest2.GetHashCode() )
       {
       ++iCountErrors;	
       printerr( "Error_100aa! Expected==false");
       }
     strLoc = "Loc_300vy";
     vTest2 = new Version (5,5);
     iCountTestcases++;
     if (vTest1.GetHashCode() != vTest2.GetHashCode() )
       {
       ++iCountErrors;	
       printerr( "Error_300aa! Expected==true");
       }
     vTest1 = new Version (10,10,10);
     vTest2 = new Version (10,10,2);
     strLoc = "Loc_400vy";
     iCountTestcases++;
     if (vTest1.GetHashCode() == vTest2.GetHashCode() )
       {
       ++iCountErrors;	
       printerr( "Error_400aa! Expected==false");
       }
     strLoc = "Loc_600vy";
     vTest2 = new Version (10,10,10);
     iCountTestcases++;
     if (vTest1.GetHashCode() != vTest2.GetHashCode() )
       {
       ++iCountErrors;	
       printerr( "Error_600aa! Expected==true");
       }
     vTest1 = new Version (550,500,2,7);
     vTest2 = new Version (550,500,2,5);
     strLoc = "Loc_700vy";
     iCountTestcases++;
     if (vTest1.GetHashCode() == vTest2.GetHashCode() )
       {
       ++iCountErrors;	
       printerr( "Error_700aa! Expected==false");
       }
     strLoc = "Loc_600vy";
     vTest2 = new Version (550,500,2,7);
     iCountTestcases++;
     if (vTest1.GetHashCode() != vTest2.GetHashCode() )
       {
       ++iCountErrors;	
       printerr( "Error_900aa! Expected==true");
       }
     strLoc = "Loc_100bb";
     vTest1 = new Version (550,500);
     vTest2 = new Version (550,500,2,7);
     iCountTestcases++;
     if (vTest1.GetHashCode() == vTest2.GetHashCode() )
       {
       ++iCountErrors;	
       printerr( "Error_100xx! Expected==false");
       }
     strLoc = "Loc_110zz";
     vTest1 = new Version (Int32.MaxValue,500);
     vTest2 = new Version (550,500,2,0);
     iCountTestcases++;
     if (vTest1.GetHashCode() == vTest2.GetHashCode() )
       {
       ++iCountErrors;	
       printerr( "Error_100xx! Expected==false");
       }
     strLoc = "Loc_120zz";
     vTest1 = new Version (5,5);
     vTest2 = new Version (5,5,0,0);
     iCountTestcases++;
     if (vTest1.GetHashCode() == vTest2.GetHashCode() )
       {
       ++iCountErrors;	
       printerr( "Error_120xx! Expected==false value==" + vTest1.Equals(vTest2));
       }
     } catch (Exception exc_general ) {
     ++iCountErrors;
     Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy!  strLoc=="+ strLoc +", exc_general=="+exc_general.ToString());
     }
   if ( iCountErrors == 0 )
     {
     Console.WriteLine( "paSs. "+s_strTFName+" ,iCountTestcases=="+iCountTestcases.ToString());
     return true;
     }
   else
     {
     Console.WriteLine("FAiL! "+s_strTFName+" ,iCountErrors=="+iCountErrors.ToString()+" , BugNums?: "+s_strActiveBugNums );
     return false;
//.........这里部分代码省略.........
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:101,代码来源:co8595gethashcode.cs


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