C # advanced (4) structure, partial classification and object class

Source: Internet
Author: User

1. structure

the structure and class are almost the same, when defining, you only need to class written as struct . Defining a function for a structure is the same as defining a function for a class.

When should I use the structure? In some cases, we only need a small data structure. If classes are used, the performance will be compromised, and the structure is suitable.

Note that the structure is a value type, while the class is a reference type. The structure does not support inheritance. during compilation, the compiler always provides a constructor without parameters; constructors without parameters cannot be defined in the structure.

 

2. Classification

sometimes, multiple people may access the same class. We may put the same class, interface, or structure in different files, you only need to interface Add partial keyword.

For example, the following two different source codes are located in different files. during compilation, the system automatically createsTestoneClass, merge the methods in the two files.

Partial class testone {

Public void methodone (){}

}

 

Partial class testone {

Public void methodtwo (){}

}

 

III,ObjectClass.

all . net classes are derived from system. object .

Since all are derived fromSystem. ObjectIn this way, we can directly use some specific methods. For exampleTostring ()It is a convenient way to obtain the string representation of an object.

 

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.