合并两个或多个绑定列表 [英] Combining Two or More Binding Lists

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

问题描述

我对C#编码还很陌生,最近又开始深入研究列表.
我有2个有些相关的绑定列表.
我有两个包含完全不同的数据的列表.是否可以将这两个列表合并为一个列表?这样做的最好方法是将2个绑定列表传递到一个类中,然后将它们组合在一起并返回另一个类吗?
感谢您提供的所有帮助.

I am fairly new to C# coding and have started delving into lists a lot lately.
I have 2 binding lists that are somewhat related.
I have two lists that contain completely different pieces of data. Is it possible to combine these 2 lists into one list ? Is the best way to go about this to pass the 2 binding lists into a class and then combine them and return another class ?
Thanks for any and all help.

listHouse= new BindingList<MyObject>();
listHouse.Add(new MyObject(1, "Outdoor"));
listHouse.Add(new MyObject(2, "Hardware"));
listHouse.Add(new MyObject(3, "Tools"));
listHouse.Add(new MyObject(4, "Books"));
listHouse.Add(new MyObject(5, "Appliances"));

listColors= new BindingList<MyOtherObject>();
listColors.Add(new MyObject(11, "Blue","UPC2222"));
listColors.Add(new MyObject(22, "Green", "UPC3432"));
listColors.Add(new MyObject(33, "Pink","UPC3444"));
listColors.Add(new MyObject(44, "Yellow","UPC7777"));















推荐答案

合并不同(且不相关)的数据集没有任何意义.如果您提到的2列表来自同一父级,则您可能要创建(父级类型)集合.现在,您可以将这些列表添加到该集合中.
It doesn''t make any sense to combine different (and unrelated) set of data. If the 2 list you mentioned derive from same parent then you might want to create collection (of parent type). Now you can add these lists to that collection.


这篇关于合并两个或多个绑定列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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