C # basic keywords-sizeof Operator

Source: Internet
Author: User

The sizeof operator returns the number of bytes occupied by a given type of variable. The type of the operand specified as sizeof must be unmanaged.

From Version C #2.0, applying sizeof to built-in types does not require the use of the unsafe mode.

The sizeof operator cannot be overloaded. The Return Value of the sizeof operator is of the int type. The following table lists some constant values, which correspond to the sizeof expressions with some built-in types as operands.

For all other types (including structures), the sizeof operator can only be used in insecure code blocks. The result of the sizeof operator is defined by the implementation and belongs to the value rather than the constant.

When sizeof is applied to an operand with a structure type, the result is the total number of bytes occupied by this type of variable (including all fill bits ).

Although the marshal. sizeof method can be used, the value returned by this method is not always the same as the value returned by sizeof.

Inclual. sizeof returns the size after the mail type, while sizeof returns the size allocated during the Common Language Runtime (including all fills ).

 

C # basic keywords-sizeof Operator

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.