Farseer

导航

C# Programming Language学习笔记(五)

第十章 类
1.The abstract modifier is used to indicate that a class is incomplete and that it is intended to be used only as a base class. An abstract class differs from a nonabstract class in the following ways.
   An abstract class cannot be instantiated directly, and it is a compile-time error to use the new operator on an abstract class. Although it is possible to have variables and values whose compile-time types are abstract, such variables and values will necessarily either be null or contain references to instances of nonabstract classes derived from the abstract types
  An abstract class is permitted (but not required) to contain abstract members.
  An abstract class cannot be sealed.
  abstract修饰符用来表征一个类没有实现它是设计只用做基类的.抽象类于非抽象类在下列方面有所不同:
   抽象类不能被直接实例化,在一个抽象类上应用new操作符是一个编译时错误.尽管可以变量和值在编译时的类型是抽象的,但这些变量和值必须要么为null,要么存储继承自抽象类型的非抽象类的实例的引用.
   抽象类可以(不是必须)包含抽象成员.
   抽象类不能是封闭的.

2.When a nonabstract class is derived from an abstract class, the nonabstract class must include actual implementations of all inherited abstract members, thereby overriding those abstract members. 
   当非抽象类继承一个抽象类时,非抽象类必须包含所有继承的抽象成员的实现,因此覆盖所有的抽象成员.
3.The sealed modifier is primarily used to prevent unintended derivation, but it also enables certain run-time optimizations. In particular, because a sealed class is known to never have any derived classes, it is possible to transform virtual function member invocations on sealed class instances into nonvirtual invocations.
sealed修饰符主要用来阻止无意的继承,但是它也使运行时优化.特别地,因为封闭类被认为是不会有任何继承类,所以可以把封闭类实例中的虚函数转化成非虚函数.
4.The direct base class of a class type must not be any of the following types: System.Array, System.Delegate, System.Enum, or System.ValueType.
类的直接基类不能是下列类型中的任一个:System.Array,System.Delegate,System.Enum,System.ValueTyp.

posted on 2005-10-23 15:25  佛西亚  阅读(238)  评论(0编辑  收藏  举报