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 4 6235
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.com
"Ant" <An*@discussions.microsoft.comwrote in message
news:19**********************************@microsof t.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
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.com
"Ant" <An*@discussions.microsoft.comwrote in message
news:19**********************************@microsof t.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
Ant <An*@discussions.microsoft.comwrote:
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.Substring, using a StringBuilder to append each of the
characters you're interested in - but it would make life considerably
messier.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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
|
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...
|
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)....
|
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:...
|
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...
| |
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
...
|
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
|
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...
|
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...
|
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 =...
|
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,...
| |
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...
|
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
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,...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
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...
| |