我有一个包含书的集合类。我有一个删除方法,我想要使用,并且是在添加书籍之后。这里是我的书:删除集合类c中的项#
myList<Book> lst = new myList<Book>();
lst.addItem(new Book("Dumas", "Alexandre", "The Count Of Monte Cristo", 1844));
lst.addItem(new Book ("Clark", "Arthur C", "Rendezvous with Rama", 1972));
lst.addItem(new Book("Dumas", "Alexandre", "The Three Musketeers", 1844)); ;
lst.addItem((new Book ("Defoe", "Daniel", "Robinson Cruise", 1719)));
lst.addItem(new Book ("Clark", "Arthur C", "2001: A space Odyssey", 1968));
我的删除方法是这样的:
public void removeItem(T item)
{
Array.Resize(ref items, items.Count() -2);
}
所以,如果我想删除例如,从列表中的第一本书,我试图做的:
lst.removeItem(0);
,但我得到一个错误,指出“没有重载方法‘的removeItem’取0参数”
我做什么IM wron G?
你为什么不使用'List'?这是作业吗? –
Dai
2013-03-14 10:26:44
你能举一个更完整的例子吗? myList是你写的类型吗?你为什么不使用'System.Collections.Generic.List'? –
2013-03-14 10:26:51
为什么不使用标准的'List'?它有一个内置的'Remove'方法。http://msdn.microsoft.com/en-us/library/cd666k3e.aspx – Arran 2013-03-14 10:27:07