473,808 Members | 2,792 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 5580
> 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
4316
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
2929
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
23546
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
5990
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
2734
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
9721
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9600
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
10628
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
9195
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
7651
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
6880
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
5547
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
3859
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3011
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.