-
Implements 语句
指定一个或多个接口或接口成员,这些接口或接口成员必须在它们所在的类或结构定义中实现。
Implements interfacename [, ...]
-or-
Implements interfacename.interfacemember [, ...]
部件
-
interfacename
必选。 一个接口,其属性、过程和事件将由类或结构中对应的成员来实现。 -
interfacemember
必选。 正被实现的接口的成员。
备注
接口是表示该接口封装的成员(属性、过程和事件)的原型集合。 接口只包含成员的声明;类和结构实现这些成员。
Implements 语句必须紧跟在 Class 或 Structure 语句的后面。
当实现接口时,必须实现该接口中声明的所有成员。 省略任何成员被认为是语法错误。 若要实现单个成员,您在类或结构中声明该成员时要指定 Implements 子句 (Visual Basic) 关键字(它与 Implements 语句是分离的)。 有关更多信息,请参见 接口 (Visual Basic)。
类可以使用属性和过程的 Private (Visual Basic) 实现,但只能通过将实现类的实例转换为被声明为接口类型的变量来访问这些成员。
示例
下面的示例演示如何使用 Implements 语句来实现接口的成员。 该示例使用事件、属性和过程定义一个名为 ICustomerInfo 的接口。 类 customerInfo 实现该接口中定义的所有成员。
VB
Public Interface ICustomerInfo
Event updateComplete()
Property customerName() As String
Sub updateCustomerStatus()
End Interface
Public Class customerInfo
Implements ICustomerInfo
' Storage for the property value.
Private customerNameValue As String
Public Event updateComplete() Implements ICustomerInfo.updateComplete
Public Property CustomerName() As String _
Implements ICustomerInfo.customerName
Get
Return customerNameValue
End Get
Set(ByVal value As String)
' The value parameter is passed to the Set procedure
' when the contents of this property are modified.
customerNameValue = value
End Set
End Property
Public Sub updateCustomerStatus() _
Implements ICustomerInfo.updateCustomerStatus
' Add code here to update the status of this account.
' Raise an event to indicate that this procedure is done.
RaiseEvent updateComplete()
End Sub
End Class
请注意,类 customerInfo 在单独的源代码行上使用 Implements 语句,以指示该类实现 ICustomerInfo 接口的所有成员。 然后,该类中的每个成员使用 Implements 关键字作为其成员声明的一部分,以指示它实现该接口成员。
下面的两个过程演示如何使用上例中实现的接口。 若要测试该实现,请将这些过程添加到项目中并调用 testImplements 过程。
VB
Public Sub testImplements()
' This procedure tests the interface implementation by
' creating an instance of the class that implements ICustomerInfo.
Dim cust As ICustomerInfo = New customerInfo()
' Associate an event handler with the event that is raised by
' the cust object.
AddHandler cust.updateComplete, AddressOf handleUpdateComplete
' Set the customerName Property
cust.customerName = "Fred"
' Retrieve and display the customerName property.
MsgBox("Customer name is: " & cust.customerName)
' Call the updateCustomerStatus procedure, which raises the
' updateComplete event.
cust.updateCustomerStatus()
End Sub
Sub handleUpdateComplete()
' This is the event handler for the updateComplete event.
MsgBox("Update is complete.")
End Sub
原文链接:https://docs.microsoft.com/zh-cn/previous-versions/visualstudio/visual-studio-2010/7z6hzchx(v=vs.100)
栏目列表
最新更新
nodejs爬虫
Python正则表达式完全指南
爬取豆瓣Top250图书数据
shp 地图文件批量添加字段
爬虫小试牛刀(爬取学校通知公告)
【python基础】函数-初识函数
【python基础】函数-返回值
HTTP请求:requests模块基础使用必知必会
Python初学者友好丨详解参数传递类型
如何有效管理爬虫流量?
SQL SERVER中递归
2个场景实例讲解GaussDB(DWS)基表统计信息估
常用的 SQL Server 关键字及其含义
动手分析SQL Server中的事务中使用的锁
openGauss内核分析:SQL by pass & 经典执行
一招教你如何高效批量导入与更新数据
天天写SQL,这些神奇的特性你知道吗?
openGauss内核分析:执行计划生成
[IM002]Navicat ODBC驱动器管理器 未发现数据
初入Sql Server 之 存储过程的简单使用
这是目前我见过最好的跨域解决方案!
减少回流与重绘
减少回流与重绘
如何使用KrpanoToolJS在浏览器切图
performance.now() 与 Date.now() 对比
一款纯 JS 实现的轻量化图片编辑器
关于开发 VS Code 插件遇到的 workbench.scm.
前端设计模式——观察者模式
前端设计模式——中介者模式
创建型-原型模式