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

17.5.6 Abstract methods

阅读更多
When an instance method declaration includes an abstract modifier, that
method is said to be an abstract
method. Although an abstract method is implicitly also a virtual method, it
cannot have the modifier virtual.
An abstract method declaration introduces a new virtual method but does not
provide an implementation of that
method. Instead, non-abstract derived classes are required to provide their
own implementation by overriding that
method. Because an abstract method provides no actual implementation, the
method-body of an abstract method
simply consists of a semicolon.
Abstract method declarations are only permitted in abstract classes (§17.1.1
.1).
[Example: In the example
public abstract class Shape
{
public abstract void Paint(Graphics g, Rectangle r);
}
public class Ellipse: Shape
{
public override void Paint(Graphics g, Rectangle r) {
g.DrawEllipse(r);
}
}
public class Box: Shape
{
public override void Paint(Graphics g, Rectangle r) {
g.DrawRect(r);
}
}
the Shape class defines the abstract notion of a geometrical shape object
that can paint itself. The Paint method
is abstract because there is no meaningful default implementation. The
Ellipse and Box classes are concrete
Shape implementations. Because these classes are non-abstract, they are
required to override the Paint method
and provide an actual implementation. end example]
It is a compile-time error for a base-access (§14.5.8) to reference an
abstract method. [Example: In the example
abstract class A
{
public abstract void F();
}
C# LANGUAGE SPECIFICATION
238
class B: A
{
public override void F() {
base.F(); // Error, base.F is abstract
}
}
a compile-time error is reported for the base.F() invocation because it
references an abstract method. end
example]
An abstract method declaration is permitted to override a virtual method.
This allows an abstract class to force reimplementation
of the method in derived classes, and makes the original implementation of
the method
unavailable. [Example: In the example
using System;
class A
{
public virtual void F() {
Console.WriteLine("A.F");
}
}
abstract class B: A
{
public abstract override void F();
}
class C: B
{
public override void F() {
Console.WriteLine("C.F");
}
}
class A declares a virtual method, class B overrides this method with an
abstract method, and class C overrides
that abstract method to provide its own implementation. end example]
17.5.7 External methods
When a method declaration includes an extern modifier, the method is said
to be an external method. External
methods are implemented externally, typically using a language other than
C#. Because an external method
declaration provides no actual implementation, the method-body of an
external method simply consists of a
semicolon.
The mechanism by which linkage to an external method is achieved, is
implementation-defined.
[Example: The following example demonstrates the use of the extern modifier
in combination with a
DllImport attribute that specifies the name of the external library in
which the method is implemented:
using System.Text;
using System.Security.Permissions;
using System.Runtime.InteropServices;
class Path
{
[DllImport("kernel32", SetLastError=true)]
static extern bool CreateDirectory(string name, SecurityAttribute sa);
[DllImport("kernel32", SetLastError=true)]
static extern bool RemoveDirectory(string name);
[DllImport("kernel32", SetLastError=true)]
static extern int GetCurrentDirectory(int bufSize, StringBuilder buf);
[DllImport("kernel32", SetLastError=true)]
static extern bool SetCurrentDirectory(string name);
}
end example]
分享到:
评论

相关推荐

    Python库 | maui-17.5.8.tar.gz

    "maui-17.5.8.tar.gz"是一个Python库的压缩包,名为“maui”,版本号为17.5.8,格式为tar.gz,这是一种常见的源代码打包方式,通常包含库的源代码、文档、配置文件等。 **tar.gz文件解析** "maui-17.5.8.tar.gz"是...

    Python库 | galaxy-lib-17.5.6.tar.gz

    《Python库:galaxy-lib-17.5.6.tar.gz深度解析》 在Python的世界里,库扮演着至关重要的角色,它们为开发者提供了丰富的功能和便捷的工具,极大地提升了开发效率。今天我们要探讨的是一个名为"galaxy-lib"的Python...

    VMware17.5.zip

    VMware(虚拟机)是指通过软件模拟的具有完整硬件系统功能的、运行在一个完全隔离环境中的完整计算机系统,通过它可在一台电脑上同时运行更多的Microsoft Windows、Linux、Mac OS X、DOS系统。

    VMwareWorkstationPro17.5.2.23775571最新版 activition tool

    VMwareWorkstationPro17.5.2.23775571最新版 activition tool for patch on windows10/windows11

    CoreliGrafxOriginsprov17.5.3.3中文安装免费版(附注册机序列号)

    Corel iGrafx Origins是一款由corel公司推出的企业级办公软件,该软件的主要作用就是用于各类业务流程的分析操作,包含了FlowCharter、IDEF0、Process等实用工具,可以用于各类流程、BPMN基本协作图、BPMN多通道协作...

    Python库 | galaxy_lib-17.5.6-py2.py3-none-any.whl

    资源分类:Python库 所属语言:Python 资源全名:galaxy_lib-17.5.6-py2.py3-none-any.whl 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059

    财务通17.5.rar

    标题为"财务通17.5.rar"的文件透露出的信息不仅是一个简单的压缩包,它所含的内容指明了其背后的深层含义。首先,通过"管家婆"这一关键词,我们能够辨识出这是一款针对中小型企业财务管理的专业软件。"财贸双全II"则...

    Python库 | zesty.zbs-api-1.0.2020.11.17.5.tar.gz

    资源分类:Python库 所属语言:Python 资源全名:zesty.zbs-api-1.0.2020.11.17.5.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059

    WinHex.17.5.SR.9.rar

    标题中的"WinHex.17.5.SR.9.rar"表明这是该软件的第17.5版,Service Release 9(SR-9),通常这意味着一个稳定版本,包含了多项改进和修复。 在提供的压缩包文件中,我们能看到几个关键文件,它们各自扮演着重要的...

    TRichView v17.5.4 (2018最新版本fordelphi)

    TRichView v17.5.4,官网上说是 trial versions,但是可以正常使用,可以直接集成到delphi的工具栏中

    Python库 | gunicorn-17.5.tar.gz

    《Python库深度解析:Gunicorn-17.5》 在Python的世界里,Gunicorn(Green Unicorn)是一款广泛应用的Web服务器网关接口(WSGI)HTTP服务器,它能够有效地运行基于Python的应用程序。Gunicorn这个名字源于“Green ...

    任我行浏览器 V17.5.exe

    管家婆财贸双全软件系列V17.5安装包

    财贸双全.Net V17.5.zip

    管家婆财贸双全软件系列V17.5安装包

    财贸双全财务版 V17.5.zip

    管家婆财贸双全软件系列V17.5安装包

    管家婆工贸ERPT9 V17.5.zip

    管家婆财贸双全软件系列V17.5安装包

    管家婆工贸ERPT3 V17.5.zip

    管家婆财贸双全软件系列V17.5安装包

    管家婆工贸ERPT8 V17.5.zip

    管家婆财贸双全软件系列V17.5安装包

    任我行打印管理器 V17.5.exe

    管家婆财贸双全软件系列V17.5安装包

    管家婆财贸双全ⅡTop V17.5.zip

    管家婆财贸双全软件系列V17.5安装包

Global site tag (gtag.js) - Google Analytics