用多个派生的clas对象索引基类的集合 [英] indexing a collection of baseclass with multiple derived clas objects

查看:72
本文介绍了用多个派生的clas对象索引基类的集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我有一个问题,但我不知道该怎么做,但我将尝试(英语不是我的母语).

我正在为3D绘图包制作一个插件,而我正在努力订购"我的对象.

例如,我有一个基类和3个派生类.现在,用户会将对象添加到某种类型的集合中(我不知道这是什么),并在完成后单击按钮.

单击按钮时,一种方法开始处理列表.首先,它将需要评估总列表,并根据总列表进行一些计算.但是,完成此操作后,将需要生成所有项目.在生成时 我需要创建一个编号方案,这些编号不是所有对象的集合的索引,但是它应该是每个派生类的编号方案. (请注意,用户无法添加基类对象).

When the button is hit, a method starts to process the list. First it will need to evaluate the total list, and do some calculations based on the total list. But when that is done, it will need to generate all the items. While generating I need to create a numbering scheme, and these numbers are NOT the index of the collection with all the object but it should be a numbered scheme for each derived class. ( note that the user can’t add base class objects).

您将如何建立这种收藏?以及如何获得可靠的索引号?

对于用户端,有一个datagridview可以查看集合.如果他/她按下添加按钮(每个派生类一个),则他将添加一个对象.他还可以通过拖放操作来更改dgv中的位置并删除对象 从集合中取出.但是重要的是,当他完成所有索引都可以正确导出之后.

For the user end side, there is a datagridview to view the collection. If he/she presses an add button (one for each derived class) he adds an object. He can also change the position in the dgv by drag and drop operations and remove objects out of the collection. But important is when he is finished that all the indexes are correct to export.

我希望这很清楚,否则请让我进一步解释! 

推荐答案

杰夫

继承和索引并不真正属于彼此.

Inheritance and indexes don't really belong to each other. 

派生类可以看成是人类的科学化,这里是动物界中的上层基础类,而Homo直接派自Hominini.

A derived class can be seen as the Scientific classification of humans here is the upper base class is here the Animalia, while Homo direct derives from Hominini. 

在撰写本文时,我可能知道您的意思,但这很少见,因为它没有道理

While writing this I know maybe what you mean, but it is rare because it makes no sense

Module Module1
    Sub Main()
        Dim womans As New List(Of Woman)
        womans.Add(New Woman With {.shout = "zzzzzzzzz"})
        Console.WriteLine(DirectCast(womans(0), Hominini).shout)
        Console.ReadLine()
    End Sub
End Module
Public MustInherit Class Hominini
    Public Property shout As String
    Public Property MaleGender As Boolean
End Class
Public Class Woman
    Inherits Hominini
    Public Property Cry As String
End Class


注意,在这种情况下,您无法列出Hominini的列表,然后将其投射给Woman使其哭泣.


 Be aware you cannot make a list of Hominini in this situation and then let it Cry by casting it to Woman. 


这篇关于用多个派生的clas对象索引基类的集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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