Differences between class and struct

Source: Internet
Author: User
In C #, many data types are defined by the struct type and belong to the value type.
C # The defined class belongs to the reference type.

For specific analysis of the differences between the two, we need to mention heap and stack. Stack is a back-to-first-out data structure and a memory area supported by the processor, some local variables are stored, and the heap is a dynamically allocated memory area.

C # The value type is allocated to the stack, and the reference type is allocated to the heap;

Everything in C # is an object, including data types. Some data types in C # are defined by struct, and struct is inherited by valuetype, valuetype is inherited from the object, so the value type is also an object.

C # The Memory recycler recycles the stack memory after the stack framework ends. For example, if the stack framework is defined in the method, some variables defined in the method will be recycled after the method ends;
Objects defined in the heap can be recycled only after the last object is referenced. There is a big difference between the two.

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.