C # Getting Started Classic (fifth edition) learning notes (iii)

Source: Internet
Author: User

---------------Introduction to Object-oriented programming---------------

UML Representation Methods:

1) lower three points on the box

2) Upper box write class name

3) Box write properties and fields, for example: +description:string + Public Member-Private member Description member name string member type

4) Lower box write method, for example: +addsugar (in Amount:byte): Byte + Public member-Private member In/out/inout Data flow direction

5) The static member is underlined

6) Interface: Draw on the class name side, Lollipop type

7) Inheritance: Arrows from child class to parent class

Constructors: Constructors have the same name as the class, default constructors have no arguments, can define non-default constructors with parameters

Static members: Static members can be shared among instances of a class, and can be seen as global objects of a class

---------------Define Class---------------

class keyword definition classes

Modifier keywords for class:

Public/protected/private public class/protected class/Private class

Abstract/sealed abstract class (cannot be instantiated, can only inherit)/sealed class (cannot inherit)

Inheritance: The base class is inherited before a supported interface can be specified, not reversed, and the interface supports multiple

interface Keyword Definition interface

Modifier keywords for the interface:

Public Common Interface

---------------Define Class members---------------

Available keyword static, representing static members

Defined field available keyword ReadOnly, indicating that a value can be assigned only during the execution of a constructor, or by an initialization assignment statement

Define method Keywords:

The virtual--method can be overridden

The abstract--method must be overridden in a non-abstract derived class (used only in abstract classes)

The override--method overrides a base class method

extern--method definition put somewhere else

Define properties available get{}set{} code block, available virtual/override/abstract keyword

To explicitly hide a base class method:

1  Public classMyBaseClass2  {3       Public voiddosomething ()4      {}5  }6   Public classMyderivedclass:mybaseclass7  {8      New  Public voiddosomething ()9      {}Ten}

Note the difference between hiding and overriding

Implementation of the interface:

1) All interface members are public

2) interface members cannot contain code bodies

3) interface cannot define field members

4) Interface members cannot be defined with the keyword static/virtual/abstract/sealed

5) Type-defined member is forbidden

To implement an interface in a class:

The class that implements the interface must contain the implementation code for all members of the interface, and must match the specified signature (including matching the specified get and set blocks), and must be public

Can be implemented by using the keyword virtual or abstract, or by implementing an interface on a base class

If an interface member is explicitly implemented, that member can only be accessed through the interface and cannot be accessed through the class

For example:

1  Public class Myclass:imyinterface 2 {3       Public void imyinterface.dosomething () 4      {}5       Public void Dosomethingelse () 6      {}7 }

Since DoSomething () is explicitly implemented, Dosomethingelse () is implicitly implemented, which can then be accessed directly from the MyClass object instance.

Partial class Definitions:

Placing the definition of a class in multiple files requires that the partial keyword be used for each of these definition files, such as:

1  Public Partial class MyClass 2 {3    ... 4 }

In another file

Class MyClass{ ... 4}   

C # Getting Started Classic (fifth edition) learning notes (iii)

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.