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


C# UIntPtr.ToUInt32方法代码示例

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


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

示例1: PosTest1

    public bool PosTest1()
    {
        bool retVal = true;

        const string c_TEST_ID = "P001";
        const string c_TEST_DESC = "PosTest1: random UInt32 value";
        string errorDesc;

        UIntPtr actualUIntPtr;
        bool actualResult;

        TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);
        try
        {
            UInt32 ui = this.GetUInt32();
            actualUIntPtr = new UIntPtr(ui);

            actualResult = actualUIntPtr.ToUInt32() == ui;

            if (!actualResult)
            {
                errorDesc = "Actual UIntPtr value is not " + ui + " as expected: Actual(" + actualUIntPtr + ")";
                TestLibrary.TestFramework.LogError("001" + " TestId-" + c_TEST_ID, errorDesc);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            errorDesc = "Unexpected exception: " + e;
            TestLibrary.TestFramework.LogError("002" + " TestId-" + c_TEST_ID, errorDesc);
            retVal = false;
        }

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

示例2: 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";
   UInt32 iValue;
   UIntPtr ip1;
   try {
   strLoc = "Loc_743wg";
   iValue = 16;
   ip1 = new UIntPtr(iValue);
   iCountTestcases++;
   if(ip1.ToUInt32() != iValue){
   iCountErrors++;
   Console.WriteLine("Err_2975sf! Wrong value returned");
   }
   strLoc = "Loc_0084wf";
   iValue = 0;
   ip1 = new UIntPtr(iValue);
   iCountTestcases++;
   if(ip1.ToUInt32() != iValue){
   iCountErrors++;
   Console.WriteLine("Err_974325sdg! Wrong value returned");
   }
   strLoc = "Loc_93476sdg";
   iValue = UInt32.MaxValue;
   ip1 = new UIntPtr(iValue);
   iCountTestcases++;
   if(ip1.ToUInt32() != iValue){
   iCountErrors++;
   Console.WriteLine("Err_07536tsg! Wrong value returned");
   }
   iValue = UInt32.MinValue;
   ip1 = new UIntPtr(iValue);
   if(ip1.ToUInt32() != iValue){
   iCountErrors++;
   Console.WriteLine("Err_9875wrsg! 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,代码行数:54,代码来源:co8543touint32.cs

示例3: VerifyPointer

    private static void VerifyPointer(UIntPtr ptr, ulong expected)
    {
        Assert.Equal(expected, ptr.ToUInt64());

        uint expected32 = (uint)expected;
        if (expected32 != expected)
        {
            Assert.Throws<OverflowException>(() => ptr.ToUInt32());
            return;
        }

        Assert.Equal(expected32, ptr.ToUInt32());

        Assert.Equal(expected.ToString(), ptr.ToString());

        Assert.Equal(ptr, new UIntPtr(expected));
        Assert.True(ptr == new UIntPtr(expected));
        Assert.False(ptr != new UIntPtr(expected));

        Assert.NotEqual(ptr, new UIntPtr(expected + 1));
        Assert.False(ptr == new UIntPtr(expected + 1));
        Assert.True(ptr != new UIntPtr(expected + 1));
    }
开发者ID:kkurni,项目名称:corefx,代码行数:23,代码来源:UIntPtr.cs

示例4: TestPointer

    private static void TestPointer(UIntPtr p, ulong expected)
    {
        ulong l = p.ToUInt64();
        Assert.Equal(expected, l);

        uint expected32 = (uint)expected;
        if (expected32 != expected)
        {
            Assert.Throws<OverflowException>(() => p.ToUInt32());
            return;
        }

        {
            uint i = p.ToUInt32();
            Assert.Equal(expected32, i);
        }

        string s = p.ToString();
        string sExpected = expected.ToString();
        Assert.Equal(s, sExpected);

        Assert.True(p == new UIntPtr(expected));
        Assert.Equal(p, new UIntPtr(expected));
        Assert.False(p == new UIntPtr(expected + 1));
        Assert.NotEqual(p, new UIntPtr(expected + 1));
        Assert.False(p != new UIntPtr(expected));
        Assert.True(p != new UIntPtr(expected + 1));
    }
开发者ID:noahfalk,项目名称:corefx,代码行数:28,代码来源: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;

        UInt32 actualUI, expectedUI;
        UIntPtr uiPtr;
        bool actualResult;

        TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);
        try
        {
            expectedUI = (UInt32)TestLibrary.Generator.GetInt32(-55);
            uiPtr = new UIntPtr(expectedUI);
            actualUI = uiPtr.ToUInt32();

            actualResult = actualUI == expectedUI;
            if (!actualResult)
            {
                errorDesc = "Actual UInt32 from UIntPtr is not " + expectedUI + " as expected: Actual(" + actualUI + ")";
                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:l1183479157,项目名称:coreclr,代码行数:36,代码来源:uintptrtouint32.cs

示例6: PosTest4

    public bool PosTest4()
    {
        bool retVal = true;

        const string c_TEST_ID = "P004";
        const string c_TEST_DESC = "PosTest4: UIntPtr with a value UInt32.MaxValue";
        string errorDesc;

        UInt32 actualUI, expectedUI;
        UIntPtr uiPtr;
        bool actualResult;

        TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);
        try
        {
            expectedUI = UInt32.MaxValue;
            uiPtr = new UIntPtr(expectedUI);
            actualUI = uiPtr.ToUInt32();

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

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

示例7: TestPointer

    private static void TestPointer(UIntPtr p, ulong expected)
    {
        ulong l = p.ToUInt64();
        Assert.Equal(l, expected);

        uint expected32 = (uint)expected;
        if (expected32 != expected)
        {
            try
            {
                uint i = p.ToUInt32();
                Assert.True(false, "ToUInt32() should have thrown.");
            }
            catch (OverflowException)
            {
            }
            return;
        }

        {
            uint i = p.ToUInt32();
            Assert.Equal(i, expected32);
        }

        String s = p.ToString();
        String sExpected = expected.ToString();
        Assert.Equal(s, sExpected);

        bool b;

        b = (p == new UIntPtr(expected));
        Assert.True(b);

        b = (p == new UIntPtr(expected + 1));
        Assert.False(b);

        b = (p != new UIntPtr(expected));
        Assert.False(b);

        b = (p != new UIntPtr(expected + 1));
        Assert.True(b);
    }
开发者ID:johnhhm,项目名称:corefx,代码行数:42,代码来源:UIntPtr.cs


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