返回继承另一个类的任何类 [英] Return any class which inherits another class

查看:118
本文介绍了返回继承另一个类的任何类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我有一个基类CodeElement和多个继承CodeElement的类。



我怎么能有一个函数返回(任何继承CodeElement的东西)?



我尝试过:



搜索有关继承的内容

解决方案

将方法声明为返回基类的实例:

公共函数MyMethod()As CodeElement 
...
结束函数

然后它可以返回从CodeElement派生的任何值

Hi
I have a base class CodeElement and multiple classes which inherit CodeElement.

How can I have a function returning (anything which inherits CodeElement)?

What I have tried:

Searching for a while about inheritance

解决方案

Declare the method as returning an instance of the base class:

Public Function MyMethod() As CodeElement
	...
End Function

It can then return any value which is derived from CodeElement


这篇关于返回继承另一个类的任何类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆