473,382 Members | 1,651 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,382 software developers and data experts.

Difference between ArrayList and List<object> ?

Hello,

Is there any difference between ArrayList and List<object? Which
one should I use ?

Thanks.

Oct 20 '06 #1
13 31221
On 20 Oct 2006 01:31:11 -0700, "Murat Ozgur" <mu********@gmail.com>
wrote:
Is there any difference between ArrayList and List<object? Which
one should I use ?
I think List< object should be better, because it uses generics; so
it is type safer than ArrayList (in which you can put everything
derived from base object class).

Oct 20 '06 #2
Not much difference really, I'd probably use List<Objectbecause then
it's clear to other people that your intention was to store a list of
Objects (or various derivative types), rather than a list of some other
specific type that would always need explicitly casting.

--
Chris Fulstow
MCP, MCTS
http://chrisfulstow.blogspot.com/
Murat Ozgur wrote:
Hello,

Is there any difference between ArrayList and List<object? Which
one should I use ?

Thanks.
Oct 20 '06 #3
Is there any difference between ArrayList and List<object? Which
one should I use ?
I'd choose to use List<objectbecause of the improved APIs on List<object>
that aren't available on ArrayList.

Best Regards,
Dustin Campbell
Developer Express Inc.
Oct 20 '06 #4
Murat,

I like the extended API of List<T>. Also, I wouldn't be surprised if
they use different growth algorithms.

Brian

Murat Ozgur wrote:
Hello,

Is there any difference between ArrayList and List<object? Which
one should I use ?

Thanks.
Oct 20 '06 #5
* Murat Ozgur wrote:
Hello,

Is there any difference between ArrayList and List<object? Which
one should I use ?
List<objectis type safe and more efficient since it doesn't require
boxing operations (converting a value type to a reference type, and vice
versa) so it could be more efficient depending on what you store in your
list.
Oct 21 '06 #6
"Angel Of Death" <af***@23o.1f.co.ukwrote in message
news:eh**********@custnews.inweb.co.uk...
>* Murat Ozgur wrote:
>Hello,

Is there any difference between ArrayList and List<object? Which
one should I use ?

List<objectis type safe and more efficient since it doesn't require
boxing operations (converting a value type to a reference type, and
vice
versa) so it could be more efficient depending on what you store in
your
list.
Claiming that "List<objectis type safe" is sort of silly.
Since it has a type of object that kind of wipes out type saftey since
everything is an object.

A better overall suggestion would be to use List<SomeType>. Then you can
talk about type safe.

Bill

Oct 21 '06 #7
"Angel Of Death" <af***@23o.1f.co.ukwrote in message
news:eh**********@custnews.inweb.co.uk...
List<objectis type safe
Of course it isn't!

List<stringis type-safe, List<SqlParameteris type-safe, but List<object>
*clearly* isn't... :-)

List<objectobjList = new List<object>;
objList.Add(new string);
objList.Add(new int);

etc
Oct 21 '06 #8
MrAsm wrote:
On 20 Oct 2006 01:31:11 -0700, "Murat Ozgur" <mu********@gmail.com>
wrote:
> Is there any difference between ArrayList and List<object? Which
one should I use ?

I think List< object should be better, because it uses generics; so
it is type safer than ArrayList (in which you can put everything
derived from base object class).
No, there is no difference in type safety. A reference to an object is
not more type safe just because you use generics.
Oct 22 '06 #9
"Göran Andersson" <gu***@guffa.comwrote in message
news:eO**************@TK2MSFTNGP04.phx.gbl...
>I think List< object should be better, because it uses generics; so
it is type safer than ArrayList (in which you can put everything
derived from base object class).

No, there is no difference in type safety. A reference to an object is not
more type safe just because you use generics.
I think what he means is that an ArrayList can store multiple types, and
there's no checking to ensure that every element of the array is the same
type as every other element.

Perhaps a more significant benefit would be "type convenient". :)

As you note, C# is type safe no matter how you store a reference. But one
nice thing about the generic types is that because the type is explicitly
stated with the collection, you don't need to cast things as they are
referenced from the collection.

Pete
Oct 22 '06 #10
Peter Duniho wrote:
"Göran Andersson" <gu***@guffa.comwrote in message
news:eO**************@TK2MSFTNGP04.phx.gbl...
>>I think List< object should be better, because it uses generics; so
it is type safer than ArrayList (in which you can put everything
derived from base object class).
No, there is no difference in type safety. A reference to an object is not
more type safe just because you use generics.

I think what he means is that an ArrayList can store multiple types, and
there's no checking to ensure that every element of the array is the same
type as every other element.
The exact same is true for List<objecttoo.
Perhaps a more significant benefit would be "type convenient". :)

As you note, C# is type safe no matter how you store a reference. But one
nice thing about the generic types is that because the type is explicitly
stated with the collection, you don't need to cast things as they are
referenced from the collection.
Yes, that is true for a list of a specific type, like List<int>, but not
for List<object>.
Oct 22 '06 #11
Please use cross posting instead of doing separate postings of the same
question in a lot of newsgroups.
Oct 22 '06 #12
"Göran Andersson" <gu***@guffa.comwrote in message
news:eQ**************@TK2MSFTNGP03.phx.gbl...
>I think what he means is that an ArrayList can store multiple types, and
there's no checking to ensure that every element of the array is the same
type as every other element.

The exact same is true for List<objecttoo.
Sorry...read "List<object>" as "List<T>".
Oct 22 '06 #13
* Mark Rae wrote:
"Angel Of Death" <af***@23o.1f.co.ukwrote in message
news:eh**********@custnews.inweb.co.uk...

>>List<objectis type safe


Of course it isn't!
I meant list<some_type! oops.
Oct 22 '06 #14

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

Similar topics

4
by: colson | last post by:
Hi, If I have a class A, and a List<List<object>> containing instances of A. How do I explicitly cast List<List<object>> as List<List<A>>?
2
by: Jeff | last post by:
..NET 2.0 I'm wondering if it is possible set the DataGridView.DataSource to a List<objectcollection. Where object is a class derived from the object class. If it's possible then my question...
9
by: Stephan Steiner | last post by:
Hi I seem to have a bit of trouble understanding one bit of how generics work: In C#, every class automatically derives from object, and inherits a bunch of properties (i.e. ToString()). Thus,...
5
by: =?Utf-8?B?UGF1bA==?= | last post by:
Hi I have a list of type object. The object has an ID as one of the elements and I would like to create another list that just has objects with unique IDs. For example in the list if I have...
2
by: AlarV | last post by:
I've created a class by using UML, and I have as objects Houses and Owners. I wanted an owner to have more than one houses, so I set navigable association and multiplicity 1...*. So in the class...
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
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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.