I've recently decided to refresh my memory regarding C# basics, so this might be trivial, but i've bumped into the following issue:
StringCollection
was used in .NET v1.0 in order to create a strongly typed collection for strings as opposed to an object
based ArrayList
(this was later enhanced by including Generic collections):
Taking a quick glance at StringCollection
definition, you can see the following:
// Summary:
// Represents a collection of strings.
[Serializable]
public class StringCollection : IList, ICollection, IEnumerable
{
...
public int Add(string value);
...
}
You can see it implements IList
, which contains the following declaration (among a few other declarations):
int Add(object value);
But not:
int Add(string value);
My first assumption was that it is possible due to the .NET framework covariance rules.
So just to make sure, I tried writing my own class which implements IList
and changed
int Add(object value);
to retrieve a string type instead of an object type, but for my surprise, when trying to compile the project, I got an compile-time error:
does not implement interface member 'System.Collections.IList.Add(object)'
Any ideas what causes this?
Thanks!