473,799 Members | 3,093 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ArrayList(IColl ection) constructor & overriden ArrayList.AddRa nge().

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(IColle ction).

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

public override void AddRange(IColle ction 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(IColl ection) 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
Nov 17 '05 #1
1 5579
> 1/ I was wondering if this is the desired behavior ?

Seems logical to me. It gives you a good hook point to monitor objects that
are added.
2 / Should'nt this specified in the ArrayList documentation ?
That would be too hard to keep up to date in the general case. It would be
better to just assume that any function may call any other function (now or
in the future), and to design your class accordingly. One really should
override a method without supporting the expected underlying behavior for
many reasons.

--
Jonathan Allen
"Sylvain" <sp******@austi n.rr.com> wrote in message
news:ea******** ******@TK2MSFTN GP12.phx.gbl... 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(IColle ction).

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

public override void AddRange(IColle ction 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(IColl ection) 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

Nov 17 '05 #2

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

Similar topics

7
6544
by: Lars-Erik Aabech | last post by:
Hi! I've got problems with serializing my collections of business objects. The objects themselves serialize fine, but the collections fail. I've got the following structure: Base collection class: Derives MarshalByValueComponent Implements ICollection, IList and ISerializable Explicitly implements the IList methods as private members, (ie. int
1
3110
by: Hasani | last post by:
I have an object called FileNode and it implements ICloneable which creates a deep copy of the FileNode. The one of the constructors for ArrayList use an ICollection as a paremeter. If I pass that constructor an array of type FileNode, when it copies the FileNode array, will it call Clone on each FileNode object, or just do a MemberwiseClone of each FileNode? I'm hoping that in the constructor they do somethine like try casting each...
9
4315
by: TT ( Tom Tempelaere ) | last post by:
Hi At one point in my application I have a single ArrayList object that I need to break up in two Arraylist objects: the beginning part up to an index, and the ending part from a certain index. I am now using ArrayList.GetRange but the documentation states that this method does not create new ArrayList objects but views into the source ArrayList object ArrayList original // .. ArrayList l1 = original.GetRange( 0, count ) ArrayList l2 =...
7
2928
by: ORC | last post by:
Hi, How to create an ArrayList from a System.Array or inserting the System.Array into the ArrayList ? Thanks Ole
7
23545
by: MrNobody | last post by:
since ArrayList implements ICollection, is there a quick way to convert an ICollection into ArrayList (besides actually iterating through each element in the ICollection and explicitly adding them to a new ArrayList instance) ??
3
1915
by: Harold A. Mackey | last post by:
I have a situation where a user must enter three int results into three textboxes, save that entry and enter another set. All sets have to be displayed in another box or grid, and when the collection of data is complete, the array of arrays must be saved. I created an array and populated the elements: string stat = new string; stat = txt1.Text.ToString(); stat = txt2.Text.ToString(); stat = txt3.Text.ToString();
1
1977
by: wrytat | last post by:
I have an arraylist storing objects that I've defined my own. The object is called Stock. And each stock has attributes like Comp, PartNo, Model, and etc. I want to bind this arraylist with a repeater. But I always get an error message: "No default member found for type Stock." This is where the error came from: <ItemTemplate>
20
5989
by: Dennis | last post by:
I use the following code for a strongly typed arraylist and it works great. However, I was wondering if this is the proper way to do it. I realize that if I want to implement sorting of the arraylist then I have to handle this with a sort method that uses comparer. I can reference the properties of the Arraylist directly such as dim mylist as new FrameList mylist.Add(new FrameStructure) mylist(0).first = "blabla..." mylist(0).second...
2
2732
by: Lubomir | last post by:
Hi, I would like to ask if the constructor ArrayList(ICollection c) performs the deep or shallow copy of "c" collection. If it perfoms just shallow copy, is there any method for doing a deep one? Thanks, Lubomir
0
9538
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10473
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10249
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10219
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9068
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7563
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6804
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5461
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3755
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.