ArrayList(ICollection) constructor & overriden ArrayList.AddRange().

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hi,

I'm encountering a very simple issue with ArrayList constructor
and AddRange() method overriding.

I'm defining a class that extends ArrayList and contains one
overriden method: AddRange(ICollection).

public class Test:ArrayList
{
public Test(Array array): base(array)
{
}

public override void AddRange(ICollection c)
{
}
}

If I create an instance of Test:
Test t = new Test(new int[]{1,2,3});

I get
t.Count = 0 instead of t.Count = 3 (what I was naively expecting)

It looks like the ArrayList(ICollection) constructor invoke the
virtual method AddRange().

1/ I was wondering if this is the desired behavior ?

-- and if yes, do you have a pointer for the coding rules of
constructors versus virtual method calls usage ?

2 / Should'nt this specified in the ArrayList documentation ?

Thanks in advance for your help.
Sylvain
--
POST BY: http://www.dotNET.us - Need .NET? Just ask, Please dotNET.us
.



Relevant Pages

  • Re: overides/loads usage
    ... #2 But why not always use overloading or shadowing rather than overriding? ... shadowing especially since to override requires the ... procedure in the derived class shadowing or overriding the new procedure ... will fire and then the constructor from class "B". ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Overriding constructors
    ... You should be able to write a constructor for your class and explicitly call ... the base implementation, effectively overriding it. ... You can also overload ... I do not necessarily consider this to be overriding so much, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Rationale behind constructor call chain... ( and comparison with C++)
    ... I think you mean class B and class A. If B extends A, then an instance of B is itself an instance of A. ... called within the A constructor, even if the overloaded function is B ... Set it after the super constructor is called. ... In you overriding methods, if it has not been set just call the super method and exit. ...
    (comp.lang.java.programmer)
  • Re: Overloading ctor doesnt work?
    ... > datetime is immutable so overriding the constructor doesn't change the ... Ahhh! ... Thanks a bunch, now this makes things much clearer. ...
    (comp.lang.python)
  • Re: custom editor for TreeView nodes
    ... You may possibly need to modify the node collection by overriding the ... ..Add and .AddRange to create your MyCheckTreeNode. ... Prev by Date: ...
    (microsoft.public.dotnet.framework.windowsforms)