Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将System.IntPtr强制转换到uint时发生System.OverflowException_C#_Overflowexception - Fatal编程技术网

C# 将System.IntPtr强制转换到uint时发生System.OverflowException

C# 将System.IntPtr强制转换到uint时发生System.OverflowException,c#,overflowexception,C#,Overflowexception,我试图将SystemInfo中的MaximumApplicationAddress保存到uint中,但出现系统溢出异常: 系统。溢出异常:算术运算导致溢出 我尝试了很多,也用谷歌搜索了很多,但没有任何帮助。如果我转换或使用十进制,没有任何帮助 下面是有问题的代码: private uint _maxAddress; public MemorySearch() { SystemInfo info; GetSystemInfo(out info); // This lin

我试图将
SystemInfo
中的
MaximumApplicationAddress
保存到
uint
中,但出现
系统溢出异常

系统。溢出异常:算术运算导致溢出

我尝试了很多,也用谷歌搜索了很多,但没有任何帮助。如果我转换或使用十进制,没有任何帮助

下面是有问题的代码:

private uint _maxAddress;

public MemorySearch()
{
    SystemInfo info;
    GetSystemInfo(out info);

    // This line throws a System.OverflowException:
    _maxAddress = (uint)info.MaximumApplicationAddress;
    resetFields();
}

以下是错误的屏幕截图:


有什么想法吗?

编译器告诉您
最大应用程序地址的大小大于
uint

请尝试改用
(64位整数):


没有从
IntPtr
uint
UInt32
)的显式或隐式转换。显式转换为
Int32
。看

如果在64位系统上调用该函数,则该函数将抛出OverflowException


如果您真的想将64位指针转换为32位值,则必须先转换为
ulong
,然后转换为
uint
,发布源代码截图通常是不好的做法。变量监视窗格显示
MaximumApplicationAddress
的值为
0x00007ffffffff
(在base-10中为
140737488289791
)。这超出了。存储在中的值的范围。
private long _maxAddress;

public MemorySearch()
{
    SystemInfo info;
    GetSystemInfo(out info);

    _maxAddress = info.MaximumApplicationAddress.ToInt64();
    resetFields();
}