C # Advanced (quad) structure, partial classes and object classes

Source: Internet
Author: User

First, the structure

Structure and class are almost the same, in the definition of the time only to write class as struct. Defining functions for structs is exactly the same as defining functions for a class.

When do you use the structure? At some point, we just need a small data structure. If the use of class words performance is a loss, and the use of the structure is more appropriate.

Note that structs are value types, and classes are reference types; structs do not support inheritance; At compile time, the compiler always provides an parameterless constructor, and no parameterless constructors are allowed in the structure.

Ii. part of the class

Sometimes, there may be more than one person accessing the same class, we may put the same class, interface or structure in different files, only need to precede the class interface structure with the partial keyword.

For example, the following two different source code is located in different files, when compiling, the system will automatically create a Testone class, merging two files in the method.

partial class testOne{
       public void MethodOne(){}
}
    partial class testOne{
       public void MethodTwo(){}
}

Three, object class.

All of them. NET classes are derived from System.Object.

Since all derive from System.Object, some of its specific methods can be used directly. For example, the most common simple ToString () method is a convenient way to get 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.