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

查看:31
本文介绍了将 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天全站免登陆