C #-classes, interfaces, constructors, destructors,

Source: Internet
Author: User

Definitions of classes and interfaces:

    • class with The class keyword is defined, and the interface is defined with the interface keyword.

    • can use Public , the internal keyword defines the accessibility of classes and interfaces;

    • class can be defined as abstract or sealed to control inheritance;

    • The parent class and the parent class interface are specified in a comma-delimited list, placed after the class or interface name and a colon.

    • In a class definition, you can specify only one parent class, and must be the first item in the list;

1. definition of Class

650) this.width=650; "style=" Float:none; "title=" 1.png "src=" http://s3.51cto.com/wyfs02/M01/6C/E2/wKioL1VVbRzhDD_ Qaaiwcxdgvlm073.jpg "alt=" Wkiol1vvbrzhdd_qaaiwcxdgvlm073.jpg "/>

2. abstract class (inheritable, cannot be instantiated )

650) this.width=650; "style=" Float:none; "title=" 2.png "src=" http://s3.51cto.com/wyfs02/M01/6C/E7/ Wkiom1vva6kyue74aabkbvai-4y541.jpg "alt=" Wkiom1vva6kyue74aabkbvai-4y541.jpg "/>

3. sealed Class (non-inheriting)

650) this.width=650; "style=" Float:none; "title=" 3.png "src=" http://s3.51cto.com/wyfs02/M02/6C/E2/ Wkiol1vvbr6gfwpeaacxn9mkvd4584.jpg "alt=" Wkiol1vvbr6gfwpeaacxn9mkvd4584.jpg "/>

4. Inheritance of classes

650) this.width=650; "style=" Float:none; "title=" 4.png "src=" http://s3.51cto.com/wyfs02/M02/6C/E7/ Wkiom1vva6xcw0lfaad00xmjn8o333.jpg "alt=" Wkiom1vva6xcw0lfaad00xmjn8o333.jpg "/>

an inner class can inherit from a common base class, but the public base class cannot inherit from an inner class.

Classes inherit from interfaces and classes, and all interface members must be implemented in a class that supports that interface.

650) this.width=650; "style=" Float:none; "title=" 5.png "src=" http://s3.51cto.com/wyfs02/M00/6C/E2/ Wkiol1vvbsdixqopaae50kmm4pe961.jpg "alt=" Wkiol1vvbsdixqopaae50kmm4pe961.jpg "/>

5. combinations of access modifiers that can be used in a class:

650) this.width=650; "style=" Float:none; "title=" 6.png "src=" http://s3.51cto.com/wyfs02/M00/6C/E7/ Wkiom1vva6jwr4qnaajn6vez_h4350.jpg "alt=" Wkiom1vva6jwr4qnaajn6vez_h4350.jpg "/>

6. the definition of the interface, the interface does not contain implementation code, are implemented in the class.

650) this.width=650; "style=" Float:none; "title=" 7.png "src=" http://s3.51cto.com/wyfs02/M01/6C/E2/ Wkiol1vvbsbqmnanaaleo5ahgai634.jpg "alt=" Wkiol1vvbsbqmnanaaleo5ahgai634.jpg "/>

7. Inheritance of interfaces

650) this.width=650; "style=" Float:none; "title=" 8.png "src=" http://s3.51cto.com/wyfs02/M01/6C/E7/ Wkiom1vva62wgtedaaesuudw21c087.jpg "alt=" Wkiom1vva62wgtedaaesuudw21c087.jpg "/>

8. System.Object base class

all classes are inherited from the System.Object

Object methods to include:

650) this.width=650; "style=" Float:none; "title=" 9.png "src=" http://s3.51cto.com/wyfs02/M02/6C/E2/ Wkiol1vvbsqhmrzraalyiuagdjy578.jpg "alt=" Wkiol1vvbsqhmrzraalyiuagdjy578.jpg "/>

650) this.width=650; "style=" Float:none; "title=" 10.png "src=" http://s3.51cto.com/wyfs02/M02/6C/E7/ Wkiom1vva7syhbwuaas4i68hi5s048.jpg "alt=" Wkiom1vva7syhbwuaas4i68hi5s048.jpg "/>

GetType () and the typeof () Use of:

650) this.width=650; "style=" Float:none; "title=" 11.png "src=" http://s3.51cto.com/wyfs02/M00/6C/E2/ Wkiol1vvbtcrp63baag2qakj7k8750.jpg "alt=" Wkiol1vvbtcrp63baag2qakj7k8750.jpg "/>

9. Constructors and destructors: The compiler automatically adds them, initializes and cleans up objects

Constructors and destructors:

    • Classes automatically have implementation code with default constructors and destructors, and we rarely need to provide our own destructors, which can be defined using accessibility, class names, and any parameters that might be required.

    • The constructor of the base class is executed before the constructor of the derived class.

    • Use This and the Base constructor Initialization keywords, you can control the execution order of these constructors in the class;

Constructor Execution Order:

650) this.width=650; "style=" Float:none; "title=" 12.png "src=" http://s3.51cto.com/wyfs02/M00/6C/E7/ Wkiom1vva7fimdt2aaeemhqwijy049.jpg "alt=" Wkiom1vva7fimdt2aaeemhqwijy049.jpg "/>

650) this.width=650; "style=" Float:none; "title=" 13.png "src=" http://s3.51cto.com/wyfs02/M01/6C/E2/ Wkiol1vvbtbduzwlaaqqce6_xfk880.jpg "alt=" Wkiol1vvbtbduzwlaaqqce6_xfk880.jpg "/>

Destruction function

650) this.width=650; "style=" Float:none; "title=" 14.png "src=" http://s3.51cto.com/wyfs02/M01/6C/E7/ Wkiom1vva7zjo6m-aabweb9lc2g641.jpg "alt=" Wkiom1vva7zjo6m-aabweb9lc2g641.jpg "/>

. Net Framework to ensure that the call Finalize () Method

the symbols in Class view

650) this.width=650; "style=" Float:none; "title=" 15.png "src=" http://s3.51cto.com/wyfs02/M02/6C/E2/ Wkiol1vvbtqyw0ukaajv415h3ja562.jpg "alt=" Wkiol1vvbtqyw0ukaajv415h3ja562.jpg "/>

650) this.width=650; "style=" Float:none; "title=" 16.png "src=" http://s3.51cto.com/wyfs02/M01/6C/E2/ Wkiol1vvbtydbvimaageu46q8xq418.jpg "alt=" Wkiol1vvbtydbvimaageu46q8xq418.jpg "/>

Object Browser:

View-object Browser

650) this.width=650; "style=" Float:none; "title=" 17.png "src=" http://s3.51cto.com/wyfs02/M02/6C/E7/ Wkiom1vva8vwutosaaak_jw7kz0533.jpg "alt=" Wkiom1vva8vwutosaaak_jw7kz0533.jpg "/>

Add Class , The class name you create is named after the file name.

Add-new Item

class diagram:Show Base type

650) this.width=650; "style=" Float:none; "title=" 18.png "src=" http://s3.51cto.com/wyfs02/M00/6C/E2/ Wkiol1vvbuesn9-zaahi2pykl-q687.jpg "alt=" Wkiol1vvbuesn9-zaahi2pykl-q687.jpg "/>

650) this.width=650; "style=" Float:none; "title=" 19.png "src=" http://s3.51cto.com/wyfs02/M00/6C/E7/ Wkiom1vva9chon77aakluu4m8ji527.jpg "alt=" Wkiom1vva9chon77aakluu4m8ji527.jpg "/>

650) this.width=650; "style=" Float:none; "title=" 20.png "src=" http://s3.51cto.com/wyfs02/M01/6C/E2/ Wkiol1vvbuya8lh1aajmvel7vhy877.jpg "alt=" Wkiol1vvbuya8lh1aajmvel7vhy877.jpg "/>

Class Library project:

Class Library:

    • You can create class library projects that contain only class definitions that cannot be executed directly, but must be accessed through the client code in an executable program . VS and the VCE provides various tools for creating, modifying, and testing classes

Class Series:

    • Classes can be combined into series to provide common operations or to share common features. To do this, you can inherit from the base class (which can be abstract), or implement the interface;

The Class Library project is compiled to . DLL Assembly , you can access its contents by adding a reference to the class Library project in other projects. Project-add Reference

This article comes from the "Ricky's blog" blog, please be sure to keep this source http://57388.blog.51cto.com/47388/1651610

C #-classes, interfaces, constructors, destructors,

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.