"You must know. NET"-From behind: Class and struct (Ⅳ)

Source: Internet
Author: User

Main content of this section: class and structure differences.

Ⅰ, class

  In. NET, all classes eventually inherit from the SYSTEM.OBJETCT class, so it is a reference type, and the value of the object instantiated by the class is stored in the managed heap (managed heap);

Ⅱ, structural struct

A struct is a value type, and all structures inherit from the System.ValueType class, and instances are allocated in the stack of threads;

Ⅲ, why not use class to completely replace struct

There are several places where we should consider using struct instead of class:

A. When implementing a structure that is primarily used to store data, a struct can be considered;

The b.struct variable occupies the space of the stack, so it is only used when the data volume is relatively small;

C. Array of structures with higher efficiency;

D. provide compatibility for certain and unmanaged code communications.

"You must know. NET"-From behind: Class and struct (Ⅳ)

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.