[Tip: C# intptr]Intptr VS int

來源:互聯網
上載者:User

C# contains a struct called Intptr, which aims to be the same position as void* in unmanaged world. So it will be 32bit on x32 hardware and OS and be 64bit on x63 platform. So be careful about misusing it with int. Int keeps 4 bytes on any platform.

MOre:

1. 在您調用的API函數中一定有類似表單控制代碼這樣的參數,那麼當您聲明這個函數時,您應該將它顯式地聲明為IntPtr類型。 在C#中聲明Win32API時,一定要按照WinAPI的原型來聲明,不要改變它的資料類型.

2. IntPtr   類型被設計成整數,其大小適用於特定平台。即是說,此類型的執行個體在32位硬體和作業系統中將是32位,在64位硬體和作業系統上將是64 位元. IntPtr類型可以由支援指標的語言使用,並可作為在支援與不支援指標的語言間引用資料的一種通用方式。IntPtr對象也可用於保持控制代碼。例如,IntPtr   的執行個體廣泛地用在   System.IO.FileStream   類中來保持檔案控制代碼。  

參考: http://twt716.blog.163.com/blog/static/320645352009329529191/

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.