473,386 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

problem implementing IList and ICollection

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>.Ad d(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

Aug 22 '06 #1
1 1713
Never mind, the return type should be void. I found out by changing
the return type until it stopped complaining.

- John
jjsav...@gmail.com wrote:
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>.Ad d(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
Aug 22 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: CGuy | last post by:
URGENT HELP REQUIRED FROM GURUS Hi, I have a custom object that implements ICollection and IListSource. This object has also an enumerator defined for it which implements IEnumerator and...
3
by: Chris | last post by:
Hi, the specs for System.Array are : public abstract class Array : ICloneable, IList, ICollection, IEnumerable but I can't use any of the functions presented by IList in my code ...
1
by: Paul | last post by:
Hi all, I'm trying to implement IList and keep getting an error when trying to implement GetEnumerator(). My class has a List<String> and I've been using its methods as return types for IList,...
2
by: Lucian Wischik | last post by:
Does ReadOnlyCollection<T> really implement IList<T>, like it claims to do? ... When I right-click on ReadOnlyCollection and look at its definition, it says this: public class...
6
by: nicolas.rolland | last post by:
Would anyone know the reson why IList<Tdoes not implements IList ?? This results in strange behaviours, like typeof(IList).IsAssignableFrom(typeof(List<string>)) --true...
2
by: BillG | last post by:
I have a List collection object that I need to assign to a property that is expecting a IEnumerable. How do I do that? Thanks Bill
3
by: Dansk | last post by:
Hi all, Can I assume that when I loop throw a Collection, List, IList, ICollection, ... by using foreach, I first get the element of index 0, then index 2, and so on until the last one ? ...
2
by: Tony | last post by:
Hello! According to the documentation we have the following interface IList : ICollection, IEnumerable { I can understand all the methods in this IList } interface ICollection : IEnumerable...
2
by: Tony Johansson | last post by:
Hello! The Array class implements these interfaces IClonable, IList, ICollection and IEnumerable. Note only interfaces are inherited and no classes so these interfaces will be implemented in...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.