473,569 Members | 2,791 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can't override CollectionBase. Count?

I have a simple object that inherits from CollectionBase and overrides the
Count property:

namespace MyTest
{
public class CollTest : System.Collecti ons.CollectionB ase
{
public override int Count
{
get { return 0; }
}
}
}

The compiler seems to think the Count method in the base class is not marked
virtual:

C:\develop\GUIT est\CollTest.cs (12): 'GUITest.CollTe st.Count.get' : cannot
override inherited member 'System.Collect ions.Collection Base.Count.get'
because it is not marked virtual, abstract, or override

However the help in VS.Net claims otherwise:

CollectionBase. Count Property [C#]
Gets the number of elements contained in the CollectionBase instance.
public virtual int Count {get;}

Any thoughts on why the override keyword is being rejected? Is the correct
approach to use the new keyword instead? This has different symantics and
is not preferred from our design point of view.

Thanks!

Nov 15 '05 #1
5 5906
100
Hi Eric,

Maybe it is an error in the MSDN but it is not virtual. Actually it is
indeed virtual because it is implementation of ICollection interface
property, but it is *sealed* as well. Thus cannot be overriden.

What you can do is ot add ICollection interface in the list of interfaces
implemented by your class and then hide the base Count property. This will
work as long as you use ICollection or IList inteface to get *Count*, but it
won't work if you cast your object down to the base class.

class Foo: CollectionBase, ICollection
{
new public int Count
{
get{return ...;}
}
}

HTH
B\rgds
100

"Eric Johannsen" <no*********@jo hannsen.us> wrote in message
news:mE******** **********@news svr25.news.prod igy.com...
I have a simple object that inherits from CollectionBase and overrides the
Count property:

namespace MyTest
{
public class CollTest : System.Collecti ons.CollectionB ase
{
public override int Count
{
get { return 0; }
}
}
}

The compiler seems to think the Count method in the base class is not marked virtual:

C:\develop\GUIT est\CollTest.cs (12): 'GUITest.CollTe st.Count.get' : cannot
override inherited member 'System.Collect ions.Collection Base.Count.get'
because it is not marked virtual, abstract, or override

However the help in VS.Net claims otherwise:

CollectionBase. Count Property [C#]
Gets the number of elements contained in the CollectionBase instance.
public virtual int Count {get;}

Any thoughts on why the override keyword is being rejected? Is the correct approach to use the new keyword instead? This has different symantics and
is not preferred from our design point of view.

Thanks!

Nov 15 '05 #2
The MSDN documentation does not indicate that CollectionBase is sealed:

[Serializable]
public abstract class CollectionBase : IList, ICollection, IEnumerable

Why would one seal an abstract class anyhow? The purpose of sealing a class
is to prevent further dirivation, and the purpose of an abstract class is to
force a base class to be derived from it before it can be used???
Thanks,

Eric
"100" <10*@100.com> wrote in message
news:Oc******** ******@TK2MSFTN GP11.phx.gbl...
Hi Eric,

Maybe it is an error in the MSDN but it is not virtual. Actually it is
indeed virtual because it is implementation of ICollection interface
property, but it is *sealed* as well. Thus cannot be overriden.

What you can do is ot add ICollection interface in the list of interfaces
implemented by your class and then hide the base Count property. This will
work as long as you use ICollection or IList inteface to get *Count*, but it won't work if you cast your object down to the base class.

class Foo: CollectionBase, ICollection
{
new public int Count
{
get{return ...;}
}
}

HTH
B\rgds
100

"Eric Johannsen" <no*********@jo hannsen.us> wrote in message
news:mE******** **********@news svr25.news.prod igy.com...
I have a simple object that inherits from CollectionBase and overrides the Count property:

namespace MyTest
{
public class CollTest : System.Collecti ons.CollectionB ase
{
public override int Count
{
get { return 0; }
}
}
}

The compiler seems to think the Count method in the base class is not

marked
virtual:

C:\develop\GUIT est\CollTest.cs (12): 'GUITest.CollTe st.Count.get' : cannot override inherited member 'System.Collect ions.Collection Base.Count.get'
because it is not marked virtual, abstract, or override

However the help in VS.Net claims otherwise:

CollectionBase. Count Property [C#]
Gets the number of elements contained in the CollectionBase instance.
public virtual int Count {get;}

Any thoughts on why the override keyword is being rejected? Is the

correct
approach to use the new keyword instead? This has different symantics and is not preferred from our design point of view.

Thanks!



Nov 15 '05 #3
100
Hi Eric,
No, the class is not. The Count property, though, is. Not only class can be
sealed. Virtual methods and properties can be sealed as well, which means
that they cannot be overriden.
Interface members are abstract which means virtual as well. When one
implements an interface memeber one override it. C# uses implicitly *sealed
override* modifiers if *virtual* is not set explicitly when the member is
implemented. This has happened with CollectionBase. Count.

HTH
B\rgds
100

"Eric Johannsen" <no*********@jo hannsen.us> wrote in message
news:IE******** **********@news svr25.news.prod igy.com...
The MSDN documentation does not indicate that CollectionBase is sealed:

[Serializable]
public abstract class CollectionBase : IList, ICollection, IEnumerable

Why would one seal an abstract class anyhow? The purpose of sealing a class is to prevent further dirivation, and the purpose of an abstract class is to force a base class to be derived from it before it can be used???
Thanks,

Eric
"100" <10*@100.com> wrote in message
news:Oc******** ******@TK2MSFTN GP11.phx.gbl...
Hi Eric,

Maybe it is an error in the MSDN but it is not virtual. Actually it is
indeed virtual because it is implementation of ICollection interface
property, but it is *sealed* as well. Thus cannot be overriden.

What you can do is ot add ICollection interface in the list of interfaces
implemented by your class and then hide the base Count property. This will work as long as you use ICollection or IList inteface to get *Count*,
but it
won't work if you cast your object down to the base class.

class Foo: CollectionBase, ICollection
{
new public int Count
{
get{return ...;}
}
}

HTH
B\rgds
100

"Eric Johannsen" <no*********@jo hannsen.us> wrote in message
news:mE******** **********@news svr25.news.prod igy.com...
I have a simple object that inherits from CollectionBase and overrides

the Count property:

namespace MyTest
{
public class CollTest : System.Collecti ons.CollectionB ase
{
public override int Count
{
get { return 0; }
}
}
}

The compiler seems to think the Count method in the base class is not

marked
virtual:

C:\develop\GUIT est\CollTest.cs (12): 'GUITest.CollTe st.Count.get' : cannot override inherited member 'System.Collect ions.Collection Base.Count.get' because it is not marked virtual, abstract, or override

However the help in VS.Net claims otherwise:

CollectionBase. Count Property [C#]
Gets the number of elements contained in the CollectionBase instance.
public virtual int Count {get;}

Any thoughts on why the override keyword is being rejected? Is the

correct
approach to use the new keyword instead? This has different symantics and is not preferred from our design point of view.

Thanks!


Nov 15 '05 #4
.... but Count is declared virtual (per my previous post):
public virtual int Count {get;}

Current MSDN link is:

http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemcoll ectionscollecti onbaseclasscoun ttopic.asp

.... still dazed and confused...

Eric

"100" <10*@100.com> wrote in message
news:O2******** ******@TK2MSFTN GP12.phx.gbl...
Hi Eric,
No, the class is not. The Count property, though, is. Not only class can be sealed. Virtual methods and properties can be sealed as well, which means
that they cannot be overriden.
Interface members are abstract which means virtual as well. When one
implements an interface memeber one override it. C# uses implicitly *sealed override* modifiers if *virtual* is not set explicitly when the member is
implemented. This has happened with CollectionBase. Count.

HTH
B\rgds
100

"Eric Johannsen" <no*********@jo hannsen.us> wrote in message
news:IE******** **********@news svr25.news.prod igy.com...
The MSDN documentation does not indicate that CollectionBase is sealed:

[Serializable]
public abstract class CollectionBase : IList, ICollection, IEnumerable

Why would one seal an abstract class anyhow? The purpose of sealing a class
is to prevent further dirivation, and the purpose of an abstract class is to
force a base class to be derived from it before it can be used???
Thanks,

Eric
"100" <10*@100.com> wrote in message
news:Oc******** ******@TK2MSFTN GP11.phx.gbl...
Hi Eric,

Maybe it is an error in the MSDN but it is not virtual. Actually it is
indeed virtual because it is implementation of ICollection interface
property, but it is *sealed* as well. Thus cannot be overriden.

What you can do is ot add ICollection interface in the list of interfaces implemented by your class and then hide the base Count property. This will work as long as you use ICollection or IList inteface to get *Count*, but
it
won't work if you cast your object down to the base class.

class Foo: CollectionBase, ICollection
{
new public int Count
{
get{return ...;}
}
}

HTH
B\rgds
100

"Eric Johannsen" <no*********@jo hannsen.us> wrote in message
news:mE******** **********@news svr25.news.prod igy.com...
> I have a simple object that inherits from CollectionBase and overrides the
> Count property:
>
> namespace MyTest
> {
> public class CollTest : System.Collecti ons.CollectionB ase
> {
> public override int Count
> {
> get { return 0; }
> }
> }
> }
>
> The compiler seems to think the Count method in the base class is
not marked
> virtual:
>
> C:\develop\GUIT est\CollTest.cs (12): 'GUITest.CollTe st.Count.get' :

cannot
> override inherited member

'System.Collect ions.Collection Base.Count.get' > because it is not marked virtual, abstract, or override
>
> However the help in VS.Net claims otherwise:
>
> CollectionBase. Count Property [C#]
> Gets the number of elements contained in the CollectionBase instance. > public virtual int Count {get;}
>
> Any thoughts on why the override keyword is being rejected? Is the
correct
> approach to use the new keyword instead? This has different

symantics and
> is not preferred from our design point of view.
>
> Thanks!
>



Nov 15 '05 #5
100
Eric,
How I said it is an error in MSDN. I don't know how to call it as long as we
can see in mscorlib.dll that CollectionBase. Count is sealed as well as
*Clear* method. The same goes for DictionaryBase. I think the doc generator
they use doesn't catch correctly those cases with interface implementation.
Anyway, this is not the only place in MSDN where you can find incorrect or
even wrong inforamation.

B\rgds
100

"Eric Johannsen" <no*********@jo hannsen.us> wrote in message
news:pC******** **********@news svr25.news.prod igy.com...
... but Count is declared virtual (per my previous post):
public virtual int Count {get;}

Current MSDN link is:

http://msdn.microsoft.com/library/de...us/cpref/html/ frlrfsystemcoll ectionscollecti onbaseclasscoun ttopic.asp

... still dazed and confused...

Eric

"100" <10*@100.com> wrote in message
news:O2******** ******@TK2MSFTN GP12.phx.gbl...
Hi Eric,
No, the class is not. The Count property, though, is. Not only class can

be
sealed. Virtual methods and properties can be sealed as well, which means
that they cannot be overriden.
Interface members are abstract which means virtual as well. When one
implements an interface memeber one override it. C# uses implicitly

*sealed
override* modifiers if *virtual* is not set explicitly when the member is implemented. This has happened with CollectionBase. Count.

HTH
B\rgds
100

"Eric Johannsen" <no*********@jo hannsen.us> wrote in message
news:IE******** **********@news svr25.news.prod igy.com...
The MSDN documentation does not indicate that CollectionBase is sealed:
[Serializable]
public abstract class CollectionBase : IList, ICollection, IEnumerable

Why would one seal an abstract class anyhow? The purpose of sealing a

class
is to prevent further dirivation, and the purpose of an abstract class is
to
force a base class to be derived from it before it can be used???
Thanks,

Eric
"100" <10*@100.com> wrote in message
news:Oc******** ******@TK2MSFTN GP11.phx.gbl...
> Hi Eric,
>
> Maybe it is an error in the MSDN but it is not virtual. Actually it is > indeed virtual because it is implementation of ICollection interface
> property, but it is *sealed* as well. Thus cannot be overriden.
>
> What you can do is ot add ICollection interface in the list of

interfaces
> implemented by your class and then hide the base Count property. This will
> work as long as you use ICollection or IList inteface to get
*Count*, but
it
> won't work if you cast your object down to the base class.
>
> class Foo: CollectionBase, ICollection
> {
> new public int Count
> {
> get{return ...;}
> }
> }
>
> HTH
> B\rgds
> 100
>
> "Eric Johannsen" <no*********@jo hannsen.us> wrote in message
> news:mE******** **********@news svr25.news.prod igy.com...
> > I have a simple object that inherits from CollectionBase and

overrides the
> > Count property:
> >
> > namespace MyTest
> > {
> > public class CollTest : System.Collecti ons.CollectionB ase
> > {
> > public override int Count
> > {
> > get { return 0; }
> > }
> > }
> > }
> >
> > The compiler seems to think the Count method in the base class is not > marked
> > virtual:
> >
> > C:\develop\GUIT est\CollTest.cs (12): 'GUITest.CollTe st.Count.get' :
cannot
> > override inherited member

'System.Collect ions.Collection Base.Count.get'
> > because it is not marked virtual, abstract, or override
> >
> > However the help in VS.Net claims otherwise:
> >
> > CollectionBase. Count Property [C#]
> > Gets the number of elements contained in the CollectionBase instance. > > public virtual int Count {get;}
> >
> > Any thoughts on why the override keyword is being rejected? Is
the > correct
> > approach to use the new keyword instead? This has different

symantics and
> > is not preferred from our design point of view.
> >
> > Thanks!
> >
>
>


Nov 15 '05 #6

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

Similar topics

3
3424
by: Marina | last post by:
Hi, I have a class that inherits from CollectionBase, and I'm trying to override its Count property. As per the documentation, this property is overridable - so I should be able to do this. So this is my code: Public Overrides ReadOnly Property Count() As Integer Get End Get End Property
2
1774
by: eastsh | last post by:
I have been looking into using the MS application block for configuration management, and I am very happy with the options it provides. Since it stores hashtables, I decided that for configuration data my app needs, I would create strongly typed collections for each config type. For instance, CarCollection dervied from CollectionBase which...
7
2061
by: Thomas Kehl | last post by:
Hello. I provided a class, which derives from the class DataView. The only thing, which I would like to do in this class am to overwrite the Property COUNT. I wars it however simply not. I get always following message from the compiler, although COUNT of the DataView (according to MSDN) is virtual. the element '...
0
1315
by: Oliver Hopton | last post by:
Hello, I'm trying to write a PageableCollection class which implements paging for me so I don't need to rely on the paging provided by the DataGrid as that generates huge viewstate when bound to a collection with a lot of items. The code below works fine when I use foreach to iterate over it but when I bind the Datagrid to an instance of...
5
1423
by: Hoang Do | last post by:
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 {
3
3160
by: Poewood | last post by:
Okay here are four classes for a pocket pc program: Input, fpositional, ComboBoxArray and TextBoxArray. The "input" class is the form. I use the fpositional class to handle most of the functions for the objects on the form, in addition the The objects are created in the fpositional class and affixed to the Input form through the fpositional...
2
1407
by: Don | last post by:
I've been trying to create a custom collection that can be bound to a combobox via the DataSource property, but I can't seem to get it to work. I've created a class that implements IList, and it seems to work okay on its own, but when I try to bind it to a combobox, the combobox doesn't show anything (and it starts having problems repainting...
8
3920
by: Yuk Tang | last post by:
I am tearing my hair out over this, since I can't see what I'm doing wrong (duh, if I knew, I wouldn't be asking the question). I am adding Field items to a Field Collection, but for some reason it wants to start from the beginning and overwrite all entries before adding the latest member. I've added a couple of msgboxes to illustrate this,...
2
2165
by: GoCoogs | last post by:
I'm trying to count how many items are in a dynamic collection. This is the code I have so far. *** Begin Code *** Public Class Rule Private _rulevars As RuleVarsCollection Private _rulename As String Public Property Name() As String Get
0
7693
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8118
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7665
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7962
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5501
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2105
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
933
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.