Csharp基础知识复习(二)

 

shallow copy, in that it doesn’t takereference type members into account.

 

If you want to create new instances of themembers in question by copying the values across (rather than the references),you need to perform a deep copy.

 

ICloneable

Clone()

 

readonly keyword

 

virtual —The method may be overridden.

abstract —The method must be overriddenin non-abstract derived classes (only permitted in abstract classes).

override —The method overrides a baseclass method (it must be used if a method is being overridden).

extern — The method definition is foundelsewhere.

 

overload:重载指的是同一个类中有两个或多个名字相同但是参数不同的方法,(:返回值不能区别函数是否重载),重载没有

关键字。

override:过载也称重写是指子类对父类中虚函数或抽象函数的“覆盖”(这也就是有些书将过载翻译为覆盖的原因),但是这

种“覆盖”和用new关键字来覆盖是有区别的。

new:覆盖指的是不同类中(基类或派生类)有两个或多个返回类型、方法名、参数都相同,但是方法体不同的方法。

但是这种覆盖是一种表面上的覆盖,所以也叫隐藏,被覆盖的父类方法是可以调用得到的。

重载覆盖的发生条件:

重载,必然发生在一个类中,函数名相同,参数类型或者顺序不同构成重载,与返回类型无关

重写,必然发生在基类和派生类中,其类函数用virtual修饰,派生类用override修饰

覆盖,在子类中写一个和基类一样名字(参数不同也算)的非虚函数,会让基类中的函数被隐藏,编译后会提示要求使用New关键字

 

 

accessors, are defined using get and setkeywords respectively, and may be used to control the access level of theproperty.

 

You can omit one or the other of theseblocks to create read-only or write-only properties (where omitting the getblock gives you write-only access, and omitting the set block gives youread-only access).

You can also include accessibility modifierson accessors — making a get block public while the set block is protected, forexample.

 

Properties can use the virtual,override,and abstract keywords just like methods

 

The accessibilities that are permitted foraccessors depend on the accessibility of the property, and it is forbidden tomake an accessor more accessible than the property to which it belongs. Thismeans that a private property cannot contain any accessibility modifiers forits accessors, whereas public properties can use all modifiers on theiraccessors.

 

使用new覆盖的方法,若用基类引用访问,结果访问的是基类的方法。而用override覆盖的方法,用基类引用访问的是派生类的

方法。

 

base keyword

this Keyword

 

this refers to an object instance, it isthe current object instance (which means you can’t use this keyword in staticmembers because static members are not part of an object instance).

 

 

Interface members are defined like classmembers except for a few important differences:

No access modifiers (public, private,protected, or internal) are allowed—all interface members are implicitlypublic.

Interface members can’t contain codebodies.

Interfaces can’t define field members.

Interface members can’t be defined usingthe keywords static, virtual, abstract, or sealed.

Type definition members are forbidden.

 

Properties defined in interfaces defineeither or both of the access blocks, get and set, which are permitted for theproperty

 

It is possible to implement interfacemembers using the keyword virtual or abstract, but not static or const.

 

partial class definitions

 

When you compile code that contains apartial method definition without an implementation, the compiler actuallyremoves the method entirely. It also removes any calls to the method.

 

你可能感兴趣的:(Csharp基础知识复习(二))