473,399 Members | 3,302 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,399 software developers and data experts.

Unable to override virtual member

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

Nov 16 '05 #1
2 1516
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" <William Le***@discussions.microsoft.com> wrote in message
news:F1**********************************@microsof t.com...
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

Nov 16 '05 #2
Save yourself some time and use Codesmith
:)http://www.ericjsmith.net/codesmith/

"Ken Kolda" <ke*******@elliemae-nospamplease.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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" <William Le***@discussions.microsoft.com> wrote in message
news:F1**********************************@microsof t.com...
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


Nov 16 '05 #3

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

Similar topics

22
by: Ruben Van Havermaet | last post by:
Hi, I have a problem using member functions in derived classes that override virtual member functions of base classes. The following pieces of (simplified) code don't work. Can anybody give...
1
by: Urs Wigger | last post by:
Hi, In a mangaed C++ wrapper class, I have some pure virtual function declarations: public __gc __abstract class CESCSAPICommand { ...... // Test only virtual bool Test(int i1, int i2) = 0;
5
by: Eric Johannsen | last post by:
I have a simple object that inherits from CollectionBase and overrides the Count property: namespace MyTest { public class CollTest : System.Collections.CollectionBase { public override int...
5
by: Darius | last post by:
I'm writing here in hopes that someone can explain the difference between the new and virtual/override keywords in C#. Specifically, what is the difference between this: public class Window {...
11
by: z_learning_tester | last post by:
Hello, yes another beginner question that I'm sure is obvious to many here :-) My book is so bad. Really. It uses the exact same example of code for using the new kw and for using virtual(in the...
5
by: Marcel Hug | last post by:
Hi NG ! I'm new in C# and I'm reading a book about the fundamentals and concepts. In the chapter Methods it's written to use virtual, if i would like to override the method in a subclass. This...
14
by: Dave Booker | last post by:
It looks like the language is trying to prevent me from doing this sort of thing. Nevertheless, the following compiles, and I'd like to know why it doesn't work the way it should: public class...
2
by: tony | last post by:
Hi! A derived class can override a method in the base class it inherits for, and even my dog knows that. More incredibly, I know and understand it too. But, can a (of course virtual in this...
1
by: Tony Johansson | last post by:
Hello! I have three classes below. These are Animal as a base class and one derived class called Cat. The main in within class Tester. If I compile the program as it is now I get the...
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: 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...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.