问题描述
如何创建简单的类定义数组?
How do I creat a simple array of class definitions?
我想达到的目标的示例;
Example of what I would like to acheive;
将class(10)视作Class? = {DerivedClassDefA,DerivedClassDefB ...}
dim classes(10) as Class?? = {DerivedClassDefA, DerivedClassDefB...}
.
.
将暗物A作为新类(3)
dim objectA as new classes(3)
.
公共函数newObject(ndx为整数)作为BaseClass
public function newObject(ndx as integer) as BaseClass
返回类(ndx)
结束功能
希望这个问题能解决,希望有人能帮忙吗?
Hope this question makes sence, Hope somone can help?
谢谢...古斯塔夫
推荐答案
例如,如果您具有以下三个类:
So for instance if you have the following three classes:
MyBaseClass->继承System.Object
DerivedClassA->继承MyBaseClass
DerivedClassB->继承MyBaseClass
MyBaseClass -> Inherits System.Object
DerivedClassA -> Inherits MyBaseClass
DerivedClassB -> Inherits MyBaseClass
然后,您可以创建一个数组,其中包含以下任一派生类:
Then you can create an array that holds either derived class with:
将类别(10)设为MyBaseClass = New MyBaseClass(){DerivedClassA_1,DerivedClassB_1}
Dim classes(10) As MyBaseClass = New MyBaseClass(){DerivedClassA_1, DerivedClassB_1}
如果要放入数组中的对象具有不同的基本类型,请使用System.Object作为数组类型.
If the objects you want to put in the array are of different base types, use System.Object as the array type.
这篇关于类定义数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!