Describes the differences between C # struct and class,

Source: Internet
Author: User

Describes the differences between C # struct and class,
1. struct and Class Definition

Struct definition use struct class definition use class struct:
Struct testDemo {int num; void action (){}}
Class:
Class testDemo {int num; void action (){}}

============================

2. Initialization of struct and class members 3. maximum difference between struct and class
  • Struct is a value type, and class is a reference type.
  • The struct is in the stack, with fast access and small space. Class in the heap, the access speed is slower than the stack, and the space is large.
  • Struct is a value type, and class is a reference type.

C # example: http://www.eyesourcecode.com/f/CSharp/1

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.