我可以创建一个列表(或等效对象),我可以组合多个类来存储数据,或者我可以用嵌套格式存储多个类。 [英] Can I create a list (or equivalent object) where I can combine the multiple classes to store the data or where I can store the multiple classes in nested format.

查看:69
本文介绍了我可以创建一个列表(或等效对象),我可以组合多个类来存储数据,或者我可以用嵌套格式存储多个类。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个类MenuItems(ID int,....,Icons_IconID int)和Icons(ID,...),我想从数据库中选择数据并将数据存储在相关的对象中。喜欢:

菜单:文件

MenuOrder:1

...

Icons_IconID:1

图标:FileIcon

...



我该怎么做?



我尝试了什么:



我试图在List中使用List,但是想不到一个如何实现这一点的可行解决方案。请帮助

I have two classes MenuItems(ID int, ...., Icons_IconID int) and Icons(ID, ...) and I want select the data from the database and store the data in the objects that are related. Like:
Menu: File
MenuOrder: 1
...
Icons_IconID:1
Icon: FileIcon
...

How can I do that?

What I have tried:

I was trying to use List within List, but couldn't think of a feasible solution on how to implement that. Please help

推荐答案

为什么不设计类来保存子类实例:

Why not design the class to hold the "sub class" instances:
public class MenuItem
   {
   public int ID { get; set; }
   ...
   private List<Icon> _Icons = new List<Icon>();  
   public List<Icon> Icons { get { return _Icons; }}
   ...
   }

然后您只需要一个List< MenuItem>把它们都拿走。

Then all you need is a List<MenuItem> to hold them all.


这篇关于我可以创建一个列表(或等效对象),我可以组合多个类来存储数据,或者我可以用嵌套格式存储多个类。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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