473,765 Members | 2,081 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 6816
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
4744
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
3254
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
4489
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
5733
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
1473
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
1882
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
39180
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
6436
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
9788
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
9568
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
9398
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
10156
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
10007
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
9951
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
9832
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6649
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
5419
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3531
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.