C
Christopher Wells
There's something I don't understand about how the CollectionBase class is
defined. I can declare:
class Derived : CollectionBase
{
}
I can instantiate this Derived class:
Derived derived = new Derived();
I cannot call an Add method as I haven't declared it:
derived.Add(1); //compiler error: Derived does not contain a definition
for Add
However CollectionBase derives from IList, IList declares Add as public
abstract, and I can successfully call Add through the IList interface:
IList ilist = derived;
ilist.Add(1);
So what is happening here:
* If neither CollectionBase nor Derived define Add, then why can I
instantiate Derived, and call Add through the IList interface?
* Or if CollectionBase does implement Add, then why can't I see it in the
Object browser and why do I get an error when I try to call it?
I understand how I'm *supposed* to use CollectionBase (I'm supposed to
define an Add method in a derived class). What I don't understand is how
CollectionBase itself is is declared or implemented: how is it that a
Derived : CollectionBase can derive from IList, and be instantiable, when
the Add method isn't defined or implemented in Derived nor in
CollectionBase, but is declared as abstract in IList?
defined. I can declare:
class Derived : CollectionBase
{
}
I can instantiate this Derived class:
Derived derived = new Derived();
I cannot call an Add method as I haven't declared it:
derived.Add(1); //compiler error: Derived does not contain a definition
for Add
However CollectionBase derives from IList, IList declares Add as public
abstract, and I can successfully call Add through the IList interface:
IList ilist = derived;
ilist.Add(1);
So what is happening here:
* If neither CollectionBase nor Derived define Add, then why can I
instantiate Derived, and call Add through the IList interface?
* Or if CollectionBase does implement Add, then why can't I see it in the
Object browser and why do I get an error when I try to call it?
I understand how I'm *supposed* to use CollectionBase (I'm supposed to
define an Add method in a derived class). What I don't understand is how
CollectionBase itself is is declared or implemented: how is it that a
Derived : CollectionBase can derive from IList, and be instantiable, when
the Add method isn't defined or implemented in Derived nor in
CollectionBase, but is declared as abstract in IList?