我有这个代码:
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 位系统上:)
关于c# - 将 intPtr 添加到 int 在 .net Framework 3.5 上生成错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6522571/