[Tip: C # intptr] intptr vs int

Source: Internet
Author: 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. the API function you call must have parameters such as a form handle. When you declare this function, you should explicitly declare it as an intptr type. When declaring WIN32API in C #, you must follow the winapi prototype and do not change its data type.

2. The intptr type is designed as an integer and its size is suitable for a specific platform. That is to say, this type of instance will be 32-bit in 32-bit hardware and operating system, and 64-bit in 64-bit hardware and operating system. the intptr type can be used by languages that support pointers and can be used to reference data between languages that support or do not support pointers. Intptr objects can also be used to keep the handle. For example, intptr instances are widely used in the system. Io. filestream class to maintain file handles.

Reference: http://twt716.blog.163.com/blog/static/320645352009329529191/

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.