473,383 Members | 1,739 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

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

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
Nov 17 '05 #1
1 5563
> 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******@austin.rr.com> wrote in message
news:ea**************@TK2MSFTNGP12.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(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

Nov 17 '05 #2

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

Similar topics

7
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...
1
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...
9
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...
7
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
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...
3
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...
1
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...
20
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...
2
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.