problem implementing IList and ICollection


J

jjsavage

Hi all,
I've got a MyList class that implements the IList<string>
interface. I can do all the IList-specific methods, but when I try to
do the ICollection ones, it says

"Error: 'Form1.MyList' does not implement interface member
'System.Collections.Generic.ICollection<string>.Add(string)'.
'MyList.Add(string)' is either static, not public, or has the wrong
return type."

Here's my Add method (list is the private member that holds the list):
public int Add(string s) {
list.addItem(s);
return list.getCount() - 1; // new item goes at end of
list
}

The help file says that Add takes an object of the type of the IList
(or ICollection), and returns an int (specifically, the position at
which the new item was added). Why does it say it's 'static, not
public, or has the wrong return type' when it's NOT static, it IS
public, and it DOES have the right return type?

Thanks,
Johon
 
Ad

Advertisements

J

jjsavage

Never mind, the return type should be void. I found out by changing
the return type until it stopped complaining.

- John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top