C # basic 1 (similarities, differences, and characteristics ),

Source: Internet
Author: User

C # basic 1 (similarities, differences, and characteristics ),

I. Main differences between value types and reference types

1. The value type is allocated to the stack, and the reference type is allocated to the stack.

2. The value type is inherited from ValueType, and the reference type is not inherited from ValueType.

3. The value type variable contains instance data, while the referenced type variable saves the reference address of its data.

4. The value type cannot be managed by GC (garbage collection mechanism), and the automatic release efficiency is higher than that of the reference type.

5. The value type cannot be inherited, but the reference type can

6. The value type cannot be null and is automatically initialized to 0. The default value of the reference type is null.

 

Ii. Differences between structures and Classes

1. The structure is a value type, and the class is a reference type.

2. The structure cannot inherit from another structure or class, and cannot be inherited

3. No default constructor is available for the structure, but you can manually add constructor. The class has the default constructor.

4. The structure does not have a structure, and the class has a destructor.

5. The structure does not use the new Keyword, but the class must use the new keyword.

 

Iii. Similarities and Differences between generic and non-generic Sets

1. a generic set can impose type constraints on the stored elements, rather than adding any type of elements to a generic set.

2. When adding a read value element to a generic set, no packing or unpacking is required. When adding a read value element to a non-generic set, binning and unboxing are required.

 

Iv. Features of Constructor

1. The method name is the same as the class name

2. No Return Value Type

3. initialize the object.

 

V. Differences between constructor and destructor
1. constructor and destructor are two special member functions described in the class body.
2. the constructor is used to initialize an object with the given value when creating the object.
3. The Destructor is used to release an object. Before deleting an object, use it for cleanup, which is opposite to the function of the constructor.

 

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.