问题描述
我有两个类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
推荐答案
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.
这篇关于我可以创建一个列表(或等效对象),我可以组合多个类来存储数据,或者我可以用嵌套格式存储多个类。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!