473,731 Members | 2,503 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ArrayList Class Vs. List Generic Class

Hello,

I need an array of objects. I am considering using either ArrayList Class
or List Generic Class.

Any guidelins regarding when to use one or the other?

Thanks
Eitan
Jun 15 '07 #1
3 6813
Eitan,

The only reason I can see using an ArrayList is when all the values that
you are going to store do not have a common base class (other than object).
However, in this case, I would suggest using List<object>, as List<object>
supports the IList<Tinterfac e still.

If the types that you are going to store in the list are all of the same
type, then use the generic class. In most instances (especially when
storing value types, because there is no boxing) you will see a performance
gain over the ArrayList class (even with reference types, there is a slight
performance gain).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Eitan" <Ei***@discussi ons.microsoft.c omwrote in message
news:39******** *************** ***********@mic rosoft.com...
Hello,

I need an array of objects. I am considering using either ArrayList Class
or List Generic Class.

Any guidelins regarding when to use one or the other?

Thanks
Eitan

Jun 15 '07 #2
ArrayList have some *build-in* methods/properties like SyncRoot or
Synchronized(Ar rayList/IList) that can be
helpful for the thread sync. if needed. I don't think that generic List have
that.

"Eitan" <Ei***@discussi ons.microsoft.c omwrote in message
news:39******** *************** ***********@mic rosoft.com...
Hello,

I need an array of objects. I am considering using either ArrayList Class
or List Generic Class.

Any guidelins regarding when to use one or the other?

Thanks
Eitan

Jun 15 '07 #3
Daniel Cigic <da**********@g mail.comwrote:
ArrayList have some *build-in* methods/properties like SyncRoot or
Synchronized(Ar rayList/IList) that can be
helpful for the thread sync. if needed. I don't think that generic List have
that.
No, although there's SynchronizedCol lection<T>.

Personally I dislike using the "synchroniz ed" version of ArrayList as
it gives a false impression of automatic thread safety. You still need
to manually lock when you need to do anything which comprises more than
one operation, eg iterating through a list.

--
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
Jun 15 '07 #4

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

Similar topics

18
4742
by: JohnR | last post by:
From reading the documentation, this should be a relatively easy thing. I have an arraylist of custom class instances which I want to search with an"indexof" where I'm passing an instance if the class where only the "searched" property has a value. I expected to get the index into the arraylist where I could then get the entire class instance. However, the 'indexof' is never calling my overloaded, overrides Equals method. Here is the...
18
3252
by: Sam | last post by:
Hi All I'm planing to write an application which allows users dynamically add their points (say you can add upto 30,000) and then draw xy graph. Should I use an array for my coordinate point storage and dynamically resize it when there is a new point or should I use ArrayList? Is speed noticable between the two? Regards,
48
4477
by: Alex Chudnovsky | last post by:
I have come across with what appears to be a significant performance bug in ..NET 2.0 ArrayList.Sort method when compared with Array.Sort on the same data. Same data on the same CPU gets sorted a lot faster with both methods using .NET 1.1, that's why I am pretty sure its a (rather serious) bug. Below you can find C# test case that should allow you to reproduce this error, to run it you will need to put 2 data files into current directory...
8
5730
by: | last post by:
I have a simple structure for example purposes I add to an array list public structure MyStruct dim counter as integer end structure dim mylist as ArrayList dim x as New MyStruct x.counter = 2
5
1472
by: blisspikle | last post by:
I figure that someone good at dotnet can look at this and give me a clue on how to easily organize this code? If there is a unique identifier like "Publisher" with a bunch of "Book" that are published under them (I used the arraylist class in the publisher class). How should the code be organized, and how can the books properties like "Name" be easily called in the main code, or searched for in the main code?
28
1871
by: wanwan | last post by:
I wrote a class and have objects from this class added to an arraylist. When I retrieve the objects from the arraylist, should I use ctype or directcast to cast them back to the original class.?
44
39178
by: Zytan | last post by:
The docs for List say "The List class is the generic equivalent of the ArrayList class." Since List<is strongly typed, and ArrayList has no type (is that called weakly typed?), I would assume List<is far better. So, why do people use ArrayList so often? Am I missing somehing? What's the difference between them? Zytan
8
6434
by: stainless | last post by:
I am not very experienced with C# and have a question regarding storing and accessing data in an array list. Whilst reading a datarow sorted on 3 fields (thID, dthID and locID - all 3 are type int), I need to store unique combinations of the 3 values in an arraylist, and then be able to access the combinations later. I am fine with the reading of the datarow and identifying the unique combinations, but am struggling with how I would then...
12
9782
by: Justin | last post by:
Ok, I give up. I can't seem to construct a decent (productive) way of sorting my arraylist. I have a structure of two elements: Structure TabStructure Dim TabName As String Dim FullFilePath As String End Structure
0
8944
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
8772
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
9443
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
9303
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...
0
8184
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
6732
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
4546
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...
0
4803
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3258
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 we have to send another system

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.