[C #] class and struct differences

Source: Internet
Author: User

From msdn

Structs differ from classes in several important ways:

  • Structs are value types (section 11.3.1 ).
  • All struct types implicitly inherit from the classSystem. valuetype(Section 11.3.2 ).
  • Assignment to a variable of a struct type createsCopyOf the value being assigned (section 11.3.3 ).
  • The default value of a struct is the value produced by setting all value type fields to their default value and all reference type fieldsNull(Section 11.3.4 ).
  • Boxing and unboxing operations are used to convert between a struct type andObject(Section 11.3.5 ).
  • The meaningThisIs different for structs (section 11.3.6 ).
  • Instance field declarations for a struct are not permitted to include variable initializers (section 11.3.7 ).
  • A struct is not permitted to declare a parameterless instance Constructor (section 11.3.8 ).
  • A struct is not permitted to declare a destructor (section 11.3.9 ).

 

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: [email protected] 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.