Entity class and struct

Source: Internet
Author: User

Seeing the structure function struct, I am confused about the difference and usage between the object class and struct.

Search for information on the Internet:

 

"Struct if the data volume is small
They are in the stack and managed stack respectively.
Struct is faster, but occupies a fast memory area ."

 

"1. What is the most basic role of a type is to store data?
2. Does its attribute have a complete public interface to access or modify data members?
3. Will I never be confident in sub-categories of types?
4. Do I have no sense of polymorphism confidence in the type?
The above is in <valid tive C #>"
If you only store data, do not design inheritance or polymorphism, you can use struct"

 

"The class is the reference type, and the structure is the value type. The reference type is allocated in the heap. Memory Management is handled by the garbage collector. Value types are allocated on the stack or in combination and released when the range is exceeded. Generally, the cost of Value Type allocation and release is smaller. However, if a large number of packing and unboxing operations are required, the value type is not as good as the reference type.
Do not define the structure unless the type has all of the following features:
It logically represents a single value, similar to the primitive type (integer, double precision, etc.
The instance size is smaller than 16 bytes.
It is immutable.
It does not need to be packed frequently ."

 

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.