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