c# – 将intPtr添加到int会在.net framework 3.5上生成错误
发布时间:2020-12-16 01:45:10 所属栏目:百科 来源:网络整理
导读:我有这个代码: lvItem.pszText = (IntPtr)(lpRemoteBuffer + Marshal.SizeOf(typeof(LV_ITEM))); 它在4.0上工作正常. 如果我将项目降级到3.5,它会给我这个错误: Operator '+' cannot be applied to operands of type 'System.IntPtr' and 'int' 任何想法如
我有这个代码:
lvItem.pszText = (IntPtr)(lpRemoteBuffer + Marshal.SizeOf(typeof(LV_ITEM))); 它在4.0上工作正常. 如果我将项目降级到3.5,它会给我这个错误: Operator '+' cannot be applied to operands of type 'System.IntPtr' and 'int' 任何想法如何解决这个问题,让它在3.5上工作 我不知道为什么它在4.0中有效? 提前致谢 解决方法
是的 – 如果你看一下
the documentation for the Addition property,你会发现运算符只是在.NET 4中引入的.顺便说一下,你不应该需要演员.
在.NET 3.5上你可能会使用: lvItem.pszText = new IntPtr(lpRemoteBuffer.ToInt64() + Marshal.SizeOf(typeof(LV_ITEM))); 当然,你需要希望你没有使用指针超过int.MaxValue的32位系统:) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |