不同对象的列表 [英] a LIST of different objects

查看:81
本文介绍了不同对象的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 我创建了一些不同的类.在所有名称为 Update()的通用方法中,它们都具有相同的名称和类型的参数.我想声明一个包含不同类的 LIST ,并调用 LIST 中每个项目的 Update().请指导我.

Hi I have created some different classes. there is a common Method in all of them named Update() with the same name and same type of arguments. I want to declare a LIST containing different classes and call the Update() of each item in LIST. please guide me.

推荐答案

创建一个暴露方法Update()的接口,然后让每个类都实现该接口.创建列表时,请输入该接口的类型.
Create an interface that exposes a method, Update(), then have each of those classes implement that interface. When you create the list, make the type that interface.


这篇关于不同对象的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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