public class ItemCollection
{
List<AbstractItem> LibCollection;
public ItemCollection()
{
LibCollection = new List<AbstractItem>();
}
public List<AbstractItem> ListForSearch()
{
return LibCollection;
}
,并在另一个类中,我写这:如何使用的foreach列表的列表上的其他类
public class Logic
{
ItemCollection ITC;
List<AbstractItem> List;
public Logic()
{
ITC = new ItemCollection();
List = ITC.ListForSearch();
}
public List<AbstractItem> search(string TheBookYouLookingFor)
{
foreach (var item in List)
{
//some code..
}
,并在foreach列表是包含什么 ,我需要工作这个列表(这个列表应该是相同的内容,libcollection)的搜索方法
从我看到的,'List'(可怕的名字btw)** **与ItemCollection.LibCollection相同的引用。 – SWeko 2013-03-19 22:25:28
定义“不包含任何内容”。它是'空'吗?还是它实例化,只是空的?在后一种情况下,我没有看到你实际上在列表中添加了什么... – David 2013-03-19 22:26:15
项目集合变得没用,你用它来封装列表,然后你公开列表!您可能需要将搜索功能移至ItemCollection,或者删除项目集合。 – 2013-03-19 22:29:59