如何在C#中将UIntPtr对象转换为IntPtr? [英] How can an UIntPtr object be converted to IntPtr in C#?

查看:1322
本文介绍了如何在C#中将UIntPtr对象转换为IntPtr?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在我的C#.NET 2.0应用程序中将 UIntPtr 对象转换为 IntPtr 如何实现呢?我不认为它是这么简单:

I need to convert an UIntPtr object to that of IntPtr in my C# .NET 2.0 application. How can this be accomplished? I don't suppose it's as simple as this:

UIntPtr _myUIntPtr = /* Some initializer value. */
object _myObject = (object)_myUIntPtr;
IntPtr _myIntPtr = (IntPtr)_myObject;


推荐答案

这应该适用于x86和x64

This should work on x86 and x64

IntPtr intPtr = unchecked((IntPtr)(long)(ulong)uintPtr);

这篇关于如何在C#中将UIntPtr对象转换为IntPtr?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆