Using IntPtr with IComparer<T>

*爱你&永不变心* 提交于 2019-12-11 18:18:44

问题


Three related questions here:

  • 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?

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

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.


回答1:


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

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



来源:https://stackoverflow.com/questions/17039736/using-intptr-with-icomparert

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!