Chapter C # Basics

Source: Internet
Author: User

2.2.3.1 declare abstract classes

Abstract class horse

{

Abstract Public void chaseafterbadguys ();

}

When abstract keywords are used for the base class, the editor will prevent this base class from being directly instantiated.

2.2.3.2 define encapsulation class

It is opposite to an abstract class and cannot be used as a base class.

Sealed class horse

{

}

Sub-classes are not allowed. Reliability, commercial purpose, and performance considerations are considered.

2.2.3.3 communication with the base class

C # allow the use of the Base keyword to access the nearest base class member.

The base keyword is valid only within the class-it cannot be called outside the class.

2.2.3.4 comparison of inheritance and ownership

Inheritance is an important tool for simulating practical problems with classes, which is useful in IS-A link modeling. For example:

A cow is a (IS-A) land animal.

However, you should be especially careful when using inheritance for modeling of ownership-HAS-A relationships. For example:

The basketball team has an indoor sports ground (HAS-A.

The house has a (HAS-A) ground.

2.2.4 object base class

All types in C # are actually derived from the object class.

2.2.5 class members

Field, constant, method, constructor, destructor, attribute, operator, time, indexer.

2.2.5.1 Field

Variable? Static readonly

2.2.5.2 constant

The constant is similar to the field, but the constant value can only be specified when it is used. It cannot be changed at ordinary times.

// Static constants (implicitly static)
Public const int compiletimeconstant = 1;
// Dynamic constant
Public static readonly runtimeconstant = 1;
2.2.5.3 Method

The method declaration in C # consists of an accessible level, a return type, a method name, and a parameter list.

Public int getnextrecordid (string tablename)

{

}

Method Parameters

Parameter Modifier

The keyword ref is used to pass parameters through reference, so that the called method can update the parameter value.

Out, Params

Overload Method

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.