473,654 Members | 3,190 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ArrayList.AddRa nge()

Ant
Hi,

I was wondering why it is that when adding a collection of controls to an
array list, you must use AddRange, instead of Add.

Thanks in advance for any ideas

Ant
Nov 3 '06 #1
4 6244
Ant,

Well, if you are calling Add, you are adding the collection itself as
the single element to the arraylist. If you are calling AddRange, then you
are going to add all the elements of the collection individually to the
list.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Ant" <An*@discussion s.microsoft.com wrote in message
news:19******** *************** ***********@mic rosoft.com...
Hi,

I was wondering why it is that when adding a collection of controls to an
array list, you must use AddRange, instead of Add.

Thanks in advance for any ideas

Ant

Nov 3 '06 #2
Ant
Thanks that makes sense, however, if I add a collection of say, strings, or
an array of numbers, I can actually iterate through them as individual
elements, not so with a collection of controls. Why the difference?

Thanks for your thoughts.

"Nicholas Paldino [.NET/C# MVP]" wrote:
Ant,

Well, if you are calling Add, you are adding the collection itself as
the single element to the arraylist. If you are calling AddRange, then you
are going to add all the elements of the collection individually to the
list.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Ant" <An*@discussion s.microsoft.com wrote in message
news:19******** *************** ***********@mic rosoft.com...
Hi,

I was wondering why it is that when adding a collection of controls to an
array list, you must use AddRange, instead of Add.

Thanks in advance for any ideas

Ant


Nov 3 '06 #3
Ant <An*@discussion s.microsoft.com wrote:
Thanks that makes sense, however, if I add a collection of say, strings, or
an array of numbers, I can actually iterate through them as individual
elements, not so with a collection of controls. Why the difference?
It's more descriptive (and simpler) in your code to call AddRange than
to iterate through.

The same can be said of many things - you could do without
String.Substrin g, using a StringBuilder to append each of the
characters you're interested in - but it would make life considerably
messier.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 3 '06 #4
Jon wrote:
It's more descriptive (and simpler) in your code to call AddRange than
to iterate through.
In addition an AddRange() method often has better performance than
repeatedly calling an Add() method, as the class can often optimise its
access and manipulation of internal data structures (e.g. if it needs
to reallocate an array it can be done in one hit), and you're making
less method calls overall.
Matt

Nov 3 '06 #5

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

Similar topics

7
2917
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
23538
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) ??
1
5740
by: Craig | last post by:
Hey Everyone - I'm trying to determine the fastest way of moving array information around and could use some help. Here's the setup: Class A stores a DateTime and an amount (a payment). Class B is functionally an array of A objects (representing a cashflow). Class C is functionally an array of B objects (representing an organization of cashflows).
1
5572
by: Sylvain | last post by:
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 {
2
1375
by: RBCC | last post by:
I have a form with a 2 textboxes and a listbox, The data is read in by a file called "memberphones" The listnbox lists names in this way (lastname,first name) sorted by the last name. the textboxes have the "lastname,first name" and the phone in the other one. Now I am stumpped about how to write the instrucution to modify a record of the arraylist. here is the whole code. Imports Microsoft.VisualBasic Imports System.IO Imports...
2
6853
by: Russ Green | last post by:
I am currently working on a small VB.NET utility that accesses the Microstation VBA object model via COM. I have this code which I am trying to get to work... The key bits of information are Dim oEl As MicroStationDGN.Element Dim oTagEl() As MicroStationDGN.TagElement Dim oArrayList As New ArrayList
11
16446
by: pmclinn | last post by:
I have a function that returns an arraylist. I want the returned arraylist to be copied into the local arraylist. What is the most efficient way of doing this? -Peter
11
16248
by: Simon Says | last post by:
Hi all, I've an arraylist A1 that contains {0,1,2,3,4,5,9,8,7} I've another arraylist A2 that contains {4,5,9} I would like to search whether if A2 is present in A1 and maybe return the first occurance index. Can anyone advise on this? Thanks, Simon
4
1448
by: | last post by:
I have three Arraylists that hold strings corresponding to addresses of an e-mail list: ArrayList masterList ArrayList optInToMasterList ArrayList optOutFromMasterList I want to know the easiest way to add all of the +contents+ of one arraylist to another.
22
15925
by: Steven Blair | last post by:
I need to perform a Deep Copy on an ArrayList. I wrote a small sample app to prove this could be done: ArrayList a = new ArrayList(); ArrayList b = new ArrayList(); a.Add("Hello"); b = (ArrayList) a.Clone();
0
8294
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
8816
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
8709
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
8494
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
7309
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
6162
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
4150
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
1924
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1597
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.