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


C# UIntPtr.GetHashCode方法代码示例

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


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

示例1: runTest

 public virtual 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";
   UIntPtr ip1;
   UInt32 iValue;
   try {
   strLoc = "Loc_743wg";
   iValue = 16;
   ip1 = new UIntPtr(iValue);
   iCountTestcases++;
   if(ip1.GetHashCode() != iValue){
   iCountErrors++;
   Console.WriteLine("Err_865sg! Wrong value returned");
   }             
   strLoc = "Loc_87453sg";
   iValue = 0;
   ip1 = new UIntPtr(iValue);
   iCountTestcases++;
   if(ip1.GetHashCode() != iValue){
   iCountErrors++;
   Console.WriteLine("Err_9743sg! Wrong value returned");
   }             
   strLoc = "Loc_87453sg";
   iValue = UInt32.MaxValue;
   ip1 = new UIntPtr(iValue);
   iCountTestcases++;
   if(ip1.GetHashCode() != 2147483647){
   iCountErrors++;
   Console.WriteLine("Err_97253rdg! Wrong value returned, {0} {1}", ip1.GetHashCode(), iValue);
   }             
   strLoc = "Loc_87453sg";
   iValue = UInt32.MinValue;
   ip1 = new UIntPtr(iValue);
   iCountTestcases++;
   if(ip1.GetHashCode() != iValue){
   iCountErrors++;
   Console.WriteLine("Err_93756sg! Wrong value returned");
   }             
   } 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+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums );
     return false;
     }
   }
开发者ID:ArildF,项目名称:masters,代码行数:56,代码来源:co8539gethashcode.cs

示例2: TestGetHashCodeRespectAllBits

 public static void TestGetHashCodeRespectAllBits()
 {
     var ptr1 = new UIntPtr(0x123456FFFFFFFF);
     var ptr2 = new UIntPtr(0x654321FFFFFFFF);
     Assert.NotEqual(ptr1.GetHashCode(), ptr2.GetHashCode());
 }
开发者ID:kkurni,项目名称:corefx,代码行数:6,代码来源:UIntPtr.cs

示例3: TestEquals

 public static void TestEquals(UIntPtr ptr1, object obj, bool expected)
 {
     if (obj is UIntPtr)
     {
         UIntPtr ptr2 = (UIntPtr)obj;
         Assert.Equal(expected, ptr1 == ptr2);
         Assert.Equal(!expected, ptr1 != ptr2);
         Assert.Equal(expected, ptr1.GetHashCode().Equals(ptr2.GetHashCode()));
     }
     Assert.Equal(expected, ptr1.Equals(obj));
     Assert.Equal(ptr1.GetHashCode(), ptr1.GetHashCode());
 }
开发者ID:kkurni,项目名称:corefx,代码行数:12,代码来源:UIntPtr.cs

示例4: TestBasics

    public static unsafe void TestBasics()
    {
        UIntPtr p;
        uint i;
        ulong l;

        if (sizeof(void*) == 4)
        {
            // Skip UIntPtr tests on 32-bit platforms
            return;
        }

        int size = UIntPtr.Size;
        Assert.Equal(size, sizeof(void*));

        TestPointer(UIntPtr.Zero, 0);

        i = 42;
        TestPointer(new UIntPtr(i), i);
        TestPointer((UIntPtr)i, i);

        i = 42;
        TestPointer(new UIntPtr(i), i);

        l = 0x0fffffffffffffff;
        TestPointer(new UIntPtr(l), l);
        TestPointer((UIntPtr)l, l);

        void* pv = new UIntPtr(42).ToPointer();
        TestPointer(new UIntPtr(pv), 42);
        TestPointer((UIntPtr)pv, 42);

        p = UIntPtr.Add(new UIntPtr(42), 5);
        TestPointer(p, 42 + 5);

        // Add is spected NOT to generate an OverflowException
        p = UIntPtr.Add(new UIntPtr(0xffffffffffffffff), 5);
        unchecked
        {
            TestPointer(p, (long)0x0000000000000004);
        }

        p = UIntPtr.Subtract(new UIntPtr(42), 5);
        TestPointer(p, 42 - 5);

        bool b;
        p = new UIntPtr(42);
        b = p.Equals(null);
        Assert.False(b);
        b = p.Equals((object)42);
        Assert.False(b);
        b = p.Equals((object)(new UIntPtr(42)));
        Assert.True(b);

        int h = p.GetHashCode();
        int h2 = p.GetHashCode();
        Assert.Equal(h, h2);

        p = new UIntPtr(42);
        i = (uint)p;
        Assert.Equal(i, 42u);
        l = (ulong)p;
        Assert.Equal(l, 42u);
        UIntPtr p2;
        p2 = (UIntPtr)i;
        Assert.Equal(p, p2);
        p2 = (UIntPtr)l;
        Assert.Equal(p, p2);
        p2 = (UIntPtr)(p.ToPointer());
        Assert.Equal(p, p2);
        p2 = new UIntPtr(40) + 2;
        Assert.Equal(p, p2);
        p2 = new UIntPtr(44) - 2;
        Assert.Equal(p, p2);

        p = new UIntPtr(0x7fffffffffffffff);
        Assert.Throws<OverflowException>(() => (uint)p);
    }
开发者ID:noahfalk,项目名称:corefx,代码行数:78,代码来源:UIntPtr.cs

示例5: PosTest2

    public bool PosTest2()
    {
        bool retVal = true;

        const string c_TEST_ID = "P002";
        const string c_TEST_DESC = "PosTest2: UIntPtr with a random Int32 value ";
        string errorDesc;

        UIntPtr uiPtr;
        int actualValue, expectedValue;
        bool actualResult;

        TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);
        try
        {
            UInt32 ui = (UInt32)TestLibrary.Generator.GetInt32(-55);
            uiPtr = new UIntPtr(ui);
            expectedValue = (Int32)ui;
            actualValue = uiPtr.GetHashCode();

            actualResult = actualValue == expectedValue;

            if (!actualResult)
            {
                errorDesc = "Actual hash code is not " + expectedValue + " as expected: Actual(" + actualValue + ")";
                TestLibrary.TestFramework.LogError("003" + " TestId-" + c_TEST_ID, errorDesc);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            errorDesc = "Unexpected exception: " + e;
            TestLibrary.TestFramework.LogError("004" + " TestId-" + c_TEST_ID, errorDesc);
            retVal = false;
        }

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

示例6: PosTest4

    public bool PosTest4()
    {
        bool retVal = true;
        try
        {
            ulong addressOne = 0x123456FFFFFFFFUL;
            ulong addressTwo = 0x654321FFFFFFFFUL;
            System.UIntPtr ipOne = new UIntPtr(addressOne);
            System.UIntPtr ipTwo = new UIntPtr(addressTwo);
            if (ipOne.GetHashCode() == ipTwo.GetHashCode())
            {
                TestLibrary.TestFramework.LogError("004", "expect different hashcodes.");
                retVal = false;
            }
        }
        catch (System.OverflowException ex)
        {
            if (System.IntPtr.Size == 4)
            {
                // ok, that's what it should be
                return retVal;
            }
            else
		   	{
                TestLibrary.TestFramework.LogError("004", "IntPtr should not have thrown an OverflowException: " + ex.ToString());
                retVal = false;
		   	}
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("004", "Unexpected exception: " + e);
            retVal = false;
        }
        return retVal;
    }
开发者ID:CheneyWu,项目名称:coreclr,代码行数:35,代码来源:uintptrgethashcode.cs


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