将IntPtr与IComparer< T>一起使用。 [英] Using IntPtr with IComparer<T>

查看:116
本文介绍了将IntPtr与IComparer< T>一起使用。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此处有三个相关问题:


  • IntPtr 结构显然未实现< > 运算符。有没有一种方法可以执行此比较而不将结构转换为int或long?

  • 为什么< > 运算符未在此结构上实现吗?

  • 我正在枚举32位进程中的窗口。似乎还包括64位进程的Windows,这很好。如何确定在IntPtr结构上使用ToInt32还是ToInt64?

  • The IntPtr structure apparently does not implement < and > operators. Is there a way to perform this comparison without converting the structure to an int or long?
  • Why are the < and > operators not implemented on this structure?
  • I am enumerating windows from a 32 bit process. Windows from 64 bit processes also seem to be included, which is fine. How can I tell whether to use ToInt32 or ToInt64 on the IntPtr structure?

上下文:Windows 7(64位),VS 2010, WinForms(32位)。

Context: Windows 7 (64 bit), VS 2010, WinForms (32 bit).

我要提取的目标窗口包括64位应用程序,例如包含小工具的Windows边栏。如果我有任何错误的假设,请告诉我。

The target windows I want to extract include 64 bit apps such as the Windows Sidebar containing gadgets. If I have taken any wrong assumptions, please let me know.

推荐答案


为什么<和>运算符未在此结构上实现?

Why are the < and > operators not implemented on this structure?

因为没有意义(在大多数情况下)比较指针的地址是小于还是大于某个其他数字或其他地址。顺便说一下,IntPtr类也提供了相等函数。

Because there is no point (in most cases) of comparing if address of a pointer is less or bigger of some other number or other address. By the way IntPtr class provides equality function too.

IntPtr.Equals

这篇关于将IntPtr与IComparer&lt; T&gt;一起使用。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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