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" <nospam-news@johannsen.us> wrote in message
news:pCwsb.12830$%d2.7306@newssvr25.news.prodigy.c om...[color=blue]
> ... but Count is declared virtual (per my previous post):
> public virtual int Count {get;}
>
> Current MSDN link is:
>
>[/color]
http://msdn.microsoft.com/library/de...us/cpref/html/[color=blue]
> frlrfsystemcollectionscollectionbaseclasscounttopi c.asp
>
> ... still dazed and confused...
>
> Eric
>
> "100" <100@100.com> wrote in message
> news:O2LnaYVqDHA.1740@TK2MSFTNGP12.phx.gbl...[color=green]
> > Hi Eric,
> > No, the class is not. The Count property, though, is. Not only class can[/color]
> be[color=green]
> > sealed. Virtual methods and properties can be sealed as well, which[/color][/color]
means[color=blue][color=green]
> > 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[/color]
> *sealed[color=green]
> > override* modifiers if *virtual* is not set explicitly when the member[/color][/color]
is[color=blue][color=green]
> > implemented. This has happened with CollectionBase.Count.
> >
> > HTH
> > B\rgds
> > 100
> >
> > "Eric Johannsen" <nospam-news@johannsen.us> wrote in message
> > news:IEvsb.12817$NF1.6081@newssvr25.news.prodigy.c om...[color=darkred]
> > > The MSDN documentation does not indicate that CollectionBase is[/color][/color][/color]
sealed:[color=blue][color=green][color=darkred]
> > >
> > > [Serializable]
> > > public abstract class CollectionBase : IList, ICollection, IEnumerable
> > >
> > > Why would one seal an abstract class anyhow? The purpose of sealing a[/color]
> > class[color=darkred]
> > > is to prevent further dirivation, and the purpose of an abstract class[/color][/color]
> is[color=green]
> > to[color=darkred]
> > > force a base class to be derived from it before it can be used???
> > > Thanks,
> > >
> > > Eric
> > > "100" <100@100.com> wrote in message
> > > news:OcV2A1UqDHA.3688@TK2MSFTNGP11.phx.gbl...
> > > > Hi Eric,
> > > >
> > > > Maybe it is an error in the MSDN but it is not virtual. Actually it[/color][/color][/color]
is[color=blue][color=green][color=darkred]
> > > > 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[/color]
> > interfaces[color=darkred]
> > > > implemented by your class and then hide the base Count property.[/color][/color][/color]
This[color=blue][color=green]
> > will[color=darkred]
> > > > work as long as you use ICollection or IList inteface to get[/color][/color][/color]
*Count*,[color=blue][color=green]
> > but[color=darkred]
> > > 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" <nospam-news@johannsen.us> wrote in message
> > > > news:mEusb.12728$ji1.4223@newssvr25.news.prodigy.c om...
> > > > > I have a simple object that inherits from CollectionBase and[/color][/color]
> overrides[color=green][color=darkred]
> > > the
> > > > > Count property:
> > > > >
> > > > > namespace MyTest
> > > > > {
> > > > > public class CollTest : System.Collections.CollectionBase
> > > > > {
> > > > > public override int Count
> > > > > {
> > > > > get { return 0; }
> > > > > }
> > > > > }
> > > > > }
> > > > >
> > > > > The compiler seems to think the Count method in the base class is[/color][/color]
> not[color=green][color=darkred]
> > > > marked
> > > > > virtual:
> > > > >
> > > > > C:\develop\GUITest\CollTest.cs(12): 'GUITest.CollTest.Count.get' :
> > > cannot
> > > > > override inherited member[/color]
> > 'System.Collections.CollectionBase.Count.get'[color=darkred]
> > > > > 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[/color][/color]
> instance.[color=green][color=darkred]
> > > > > public virtual int Count {get;}
> > > > >
> > > > > Any thoughts on why the override keyword is being rejected? Is[/color][/color][/color]
the[color=blue][color=green][color=darkred]
> > > > correct
> > > > > approach to use the new keyword instead? This has different[/color][/color]
> symantics[color=green][color=darkred]
> > > and
> > > > > is not preferred from our design point of view.
> > > > >
> > > > > Thanks!
> > > > >
> > > >
> > > >
> > >[/color]
> >
> >[/color]
>[/color]