Unable to override virtual member

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm creating a strongly-typed collection class, and am deriving from CollectionBase. I note in the docs that RemoveAt() is virtual, yet I am not able to override it. For the life of me, I cannot understand why not. (Note that this is not a question of whether I should...I understand the OnRemove event will serve my purpose.) Based on the docs, I believe I should be able to, yet when I compile with a method that overrides RemoveAt, I get an error stating I can't override it "because it is not marked virtual, abstract, or override".

I'm totally mystified, and getting really annoyed I can't seem to answer a seemingly simple question. I opened the MSIL, and saw a 'final' keyword in the CollectionBase RemoveAt() member, yet I can't find 'final' in the C# docs, and don't know whether this is affecting anything.

I would love to know the answer to this if anyone knows.

Thanks,
William
 
Looks like the docs are wrong -- this method (along with Clear() and
GetEnumerator()) do not actually appear to be virtual. I guess that makes
sense since these methods are not bound to the type of object in the
collection.

Ken


William Leary said:
I'm creating a strongly-typed collection class, and am deriving from
CollectionBase. I note in the docs that RemoveAt() is virtual, yet I am not
able to override it. For the life of me, I cannot understand why not. (Note
that this is not a question of whether I should...I understand the OnRemove
event will serve my purpose.) Based on the docs, I believe I should be able
to, yet when I compile with a method that overrides RemoveAt, I get an error
stating I can't override it "because it is not marked virtual, abstract, or
override".
I'm totally mystified, and getting really annoyed I can't seem to answer a
seemingly simple question. I opened the MSIL, and saw a 'final' keyword in
the CollectionBase RemoveAt() member, yet I can't find 'final' in the C#
docs, and don't know whether this is affecting anything.
 
Back
Top