`
talin2010
  • 浏览: 522578 次
  • 性别: Icon_minigender_1
  • 来自: 河北
社区版块
存档分类
最新评论

17.6.3 Virtual, sealed, override, and abstrac

阅读更多
A virtual property declaration specifies that the accessors of the property
are virtual. The virtual modifier
applies to both accessors of a read-write property?it is not possible for
only one accessor of a read-write
property to be virtual.
An abstract property declaration specifies that the accessors of the
property are virtual, but does not provide an
actual implementation of the accessors. Instead, non-abstract derived
classes are required to provide their own
implementation for the accessors by overriding the property. Because an
accessor for an abstract property
declaration provides no actual implementation, its accessor-body simply
consists of a semicolon.
A property declaration that includes both the abstract and override
modifiers specifies that the property is
abstract and overrides a base property. The accessors of such a property
are also abstract.
Abstract property declarations are only permitted in abstract classes (§17.1
.1.1). The accessors of an inherited
virtual property can be overridden in a derived class by including a
property declaration that specifies an
override directive. This is known as an overriding property declaration. An
overriding property declaration
does not declare a new property. Instead, it simply specializes the
implementations of the accessors of an existing
virtual property.
An overriding property declaration must specify the exact same
accessibility modifiers, type, and name as the
inherited property. If the inherited property has only a single accessor
(i.e., if the inherited property is read-only
or write-only), the overriding property must include only that accessor. If
the inherited property includes both
accessors (i.e., if the inherited property is read-write), the overriding
property can include either a single accessor
or both accessors.
An overriding property declaration may include the sealed modifier. Use of
this modifier prevents a derived
class from further overriding the property. The accessors of a sealed
property are also sealed.
Except for differences in declaration and invocation syntax, virtual,
sealed, override, and abstract accessors
behave exactly like virtual, sealed, override and abstract methods.
Specifically, the rules described in §17.5.3,
§17.5.4, §17.5.5, and §17.5.6 apply as if accessors were methods of a
corresponding form:
? A get accessor corresponds to a parameterless method with a return value
of the property type and the same
modifiers as the containing property.
? A set accessor corresponds to a method with a single value parameter of
the property type, a void return
type, and the same modifiers as the containing property.
[Example: In the example
abstract class A
{
int y;
public virtual int X {
get { return 0; }
}
public virtual int Y {
get { return y; }
set { y = value; }
}
public abstract int Z { get; set; }
}
C# LANGUAGE SPECIFICATION
246
X is a virtual read-only property, Y is a virtual read-write property, and
Z is an abstract read-write property.
Because Z is abstract, the containing class A must also be declared
abstract.
A class that derives from A is show below:
class B: A
{
int z;
public override int X {
get { return base.X + 1; }
}
public override int Y {
set { base.Y = value < 0? 0: value; }
}
public override int Z {
get { return z; }
set { z = value; }
}
}
Here, the declarations of X, Y, and Z are overriding property declarations.
Each property declaration exactly
matches the accessibility modifiers, type, and name of the corresponding
inherited property. The get accessor of
X and the set accessor of Y use the base keyword to access the inherited
accessors. The declaration of Z
overrides both abstract accessors?thus, there are no outstanding abstract
function members in B, and B is
permitted to be a non-abstract class. end example]
分享到:
评论

相关推荐

    visio教程PDF

    17.6.3 图形连接器 17.7 同时连接多个图形 17.8 拖动时连接图形 17.9 激活Snap&Glue工具栏 17.10 跳线与布线 17.11 小结 第18章 快速安排图形格局 18.1 快速安排图形格局 18.1.1 选择绘图页面中...

    Visio 2000 技术大全

    目 录 译者序 前言 ... 17.6.3 图形连接器 17.7 同时连接多个图形 17.8 拖动时连接图形 17.9 激活Snap&Glue工具栏 17.10 跳线与布线 17.11 小结 第18章 快速安排图形格局 ...

    Maven权威指南 很精典的学习教程,比ANT更好用

    Transitive Dependencies, Project Attachments, and Project Artifacts 12.5.4.6. Advanced Unpacking Options 12.5.4.7. Summarizing Dependency Sets 12.5.5. moduleSets Sections 12.5.5.1. Module ...

    亮剑.NET深入体验与实战精要2

    2.4 sealed、new、virtual、abstract与override 87 2.5 abstract class与interface 91 2.6 公共变量与属性的区别 93 2.7 参数修饰符params、out和ref的区别 96 2.8 值类型和引用类型的区别 100 2.9 结构与类的区别 ...

    亮剑.NET深入体验与实战精要3

    2.4 sealed、new、virtual、abstract与override 87 2.5 abstract class与interface 91 2.6 公共变量与属性的区别 93 2.7 参数修饰符params、out和ref的区别 96 2.8 值类型和引用类型的区别 100 2.9 结构与类的区别 ...

    openssl 编程 当前版本

    29.4.4 signed_and_enveloped 238 29.4.5 digest 238 29.4.6 encrypted 239 29.4.7 读取PEM 239 29.4.8 解码pkcs7 240 第三十章 PKCS12 241 30.1 概述 241 30.2 openss实现 241 30.3数据结构 242 30.4函数 243 ...

    Visual C++2010开发权威指南.part07

    第15章 Visual C++ 2010 MFC网络 第15章 程序设计 580 ...17.6.3 微软中间语言(MSIL) 665 17.6.4 资源 666 17.7 .NET开发应用程序的范畴 666 17.8 .NET框架类库 667 17.9 C++/CLR开发语法简介 668 17.10 小结 670

    【2023新版】系统架构设计师视频教程 下载

    有300多视频。只能展示部分│ ├─14. 计算机网络│ [288]14.1. 章节概述.mp4│ [289]14.2.1.... 最短路径问题.mp4│ [344]17.6.3. 网络与最大流量问题.mp4│ [345]17.6.4. 不确定型决策.mp4│ [346]17.6.5. 决策表

    【2023新版】系统架构设计师视频教程 下载t

    有300多视频。只能展示部分│ ├─14. 计算机网络│ [288]14.1. 章节概述.mp4│ [289]14.2.1.... 最短路径问题.mp4│ [344]17.6.3. 网络与最大流量问题.mp4│ [345]17.6.4. 不确定型决策.mp4│ [346]17.6.5. 决策表

    spring.net中文手册在线版

    17.6.3. .NET 1.1 17.6.4.AdoTemplate方法指南 17.7.异常翻译 17.8.参数管理 17.8.1. IDbParametersBuilder 17.8.2. IDbParameters 17.9. Mapping DBNull values 17.10. Basic data access operations 17.10.1. ...

    OpenSSL编程(三合一版).zip

    109 17.4.1 RSA_METHOD 109 17.4.2 RSA 110 17.5 主要函数 111 17.6编程示例 112 17.6.1密钥生成 112 17.6.2 RSA加解密运算 114 17.6.3签名与验证 117 第十八章 Openssl DSA 120 18.1 ...

    Android 3D游戏开发技术宝典-OpenGL ES 2.0 (吴亚峰) 源代码

    17.6.3 加载物体刚体类——loadrigidbody 490 17.7 铰链关节 491 17.7.1 铰链关节的基本知识 491 17.7.2 案例的运行效果 492 17.7.3 铰链关节旋转角速度的计算 493 17.7.4 3d界面渲染类——...

Global site tag (gtag.js) - Google Analytics