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.

Override and System.Collections

I have a curious question and I am sure someone else must have run into it
before.
Is it a problem with the collections class or am I misunderstanding the
keyword "Overide".
why does this compile:
----------------------------------------------------
using System;

class test {

abstract class eng

{

public eng(){}

virtual public void calc()

{ Console.WriteLine("Base");}

}

class derivedFrom : eng

{

public derivedFrom(){}

override public void calc()

{ Console.WriteLine("Derived 1");}

}

static void Main() {

derivedFrom xx=new derivedFrom();
xx.calc();

}

}

----------------------------------------------------

and this won't:
----------------------------------------------------
using System;

class test {

class col : System.Collections.CollectionBase {

public col() {}
override public void RemoveAt(int index)

{

Console.WriteLine("RemoveAt");

}
}

static void Main()

{

col x = new col();

col.RemoveAt(0);

}

}

Hoang Do, ho***@jotsite.com
Nov 16 '05 #1
5 1412
Hoang Do <ho***@jotsite.com> wrote:
I have a curious question and I am sure someone else must have run into it
before.
Is it a problem with the collections class or am I misunderstanding the
keyword "Overide".


The docs are incorrect - CollectionBase.RemoveAt isn't actually
virtual.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
Gotta wonder if the docs are right and the code is wrong (yes, I know the docs should always follow the code)... it seems like it
*should* be virtual. Or is there a particular reason why it wouldn't be?

--
Adam Clauss
ca*****@tamu.edu

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message news:MP************************@msnews.microsoft.c om...
Hoang Do <ho***@jotsite.com> wrote:
I have a curious question and I am sure someone else must have run into it
before.
Is it a problem with the collections class or am I misunderstanding the
keyword "Overide".


The docs are incorrect - CollectionBase.RemoveAt isn't actually
virtual.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #3
Adam Clauss <ca*****@tamu.edu> wrote:
Gotta wonder if the docs are right and the code is wrong (yes, I know
the docs should always follow the code)... it seems like it
*should* be virtual. Or is there a particular reason why it wouldn't
be?


I'm not sure I see why it really should be virtual. CollectionBase is
generally for strongly-typed collections. Why would you want to
override CollectionBase.RemoveAt?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4
Maybe I'm missing at what level CollectionBase is.

CollectionBase does not specify what TYPE of collection is used does it (array, linked list, etc)? Or if it does, that is where I
was mistaken.

For example I might want to do something different if removing from an array than removing from a linked list.

--
Adam Clauss
ca*****@tamu.edu

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message news:MP***********************@msnews.microsoft.co m...
Adam Clauss <ca*****@tamu.edu> wrote:
Gotta wonder if the docs are right and the code is wrong (yes, I know
the docs should always follow the code)... it seems like it
*should* be virtual. Or is there a particular reason why it wouldn't
be?


I'm not sure I see why it really should be virtual. CollectionBase is
generally for strongly-typed collections. Why would you want to
override CollectionBase.RemoveAt?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #5
Adam Clauss <ca*****@tamu.edu> wrote:
Maybe I'm missing at what level CollectionBase is.

CollectionBase does not specify what TYPE of collection is used does
it (array, linked list, etc)? Or if it does, that is where I
was mistaken.
Well, InnerList returns an ArrayList. I infer from that that it's
basically an ArrayList underneath.
For example I might want to do something different if removing from
an array than removing from a linked list.


CollectionBase provides the implementation of the list part - in other
words, you can't decide to make it a linked list if it's not already.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #6

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

Similar topics

3
by: Ed | last post by:
Greetings! I'm trying to implement own collection BaseCollection (inherited from NameObjectCollectionBase class), but my attempt to override NameObjectCollectionBase virtual method public virtual...
0
by: Craig Schneider | last post by:
// Is there any way to override the XML Serialization of the following SimpleClass // to turn off the DefaultValue of a boolean? Sure, I can override the DefaultValue from // true to false, but...
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...
2
by: Mark | last post by:
I've built a class and overroad the Equals method. I've gotten the warning below. I'm unfamiliar with the "GetHashCode" method. An explantion of the method and its relation to the warning would...
2
by: Adriano Coser | last post by:
Hello. After I converted my .net code to the new VC2005 syntax I started to get C4490 on my ExpandableObjectConverter subclass overrides. The GetProperties method is no longer called by the...
2
by: Your_Persona | last post by:
Is there a way to get effect1 with the method in effect2? ///////////////////////////////////////////////////////////////////////////////////////////// using System; using...
5
by: Ben Voigt | last post by:
Getting a C1001 internal error off the following code: I've found an alternate means of making the Node property accessible in the parent class only using a public interface, private...
5
by: taumuon | last post by:
I've got an object, Person, that supports IEquatable<Person>. It implements bool Equals(Person obj) as well as overriding bool Equals(object obj) I've got a container type that holds a member...
1
by: Anila | last post by:
Hi........ My problem is i wrote a program for drawing a line in Csharp. My code is using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.