471,326 Members | 2,607 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,326 software developers and data experts.

Generics + collections

Am I correct in thinking that C#/.NET 2.0 removes the need for a
collection for each business object you have, and allows you to create
just one collection?

Or is this just the equivalent of using Object for your collection?

Jan 31 '06 #1
4 2414
Chris,

..NET eliminates the need of creating strongly typed collection for each
business object. You can use generic collection and benefit from the stronlg
typness.

Using generics is not equivalent of having collection of Object.
Using ArrayList for example, which is collection of Object one can create
heterogeneous collection, which is not possible with generic collection
unless the type is not sepcified as Object.
--
HTH
Stoitcho Goutsev (100)

"Chris S." <sl********@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
Am I correct in thinking that C#/.NET 2.0 removes the need for a
collection for each business object you have, and allows you to create
just one collection?

Or is this just the equivalent of using Object for your collection?

Jan 31 '06 #2
I can see mountains of source code being removed in business layers
thanks to this. I realise that compile time errors occur if you create
a collection with a type and then try to use another type, e.g.

MyCollection<MyObject> coll = new MyCollection<MyObject>();
coll.Add(new MyObject());
coll.Add("test");

but what I meant was internally, there can't be a huge difference
between an Object being passed around?

Jan 31 '06 #3

"Chris S." <sl********@gmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
I can see mountains of source code being removed in business layers
thanks to this. I realise that compile time errors occur if you create
a collection with a type and then try to use another type, e.g.

MyCollection<MyObject> coll = new MyCollection<MyObject>();
coll.Add(new MyObject());
coll.Add("test");

but what I meant was internally, there can't be a huge difference
between an Object being passed around?


Most people wouldn't have bothered creating typesafe collections for
internal use only - that's usually reserved for where you have collection
valued public properties.

Before you go and automatically change all your code watch out for the fact
that generic collections are not totally backward compatible - eg. IList<T>
does not derive from IList.

Note also that List<any struct> is more efficient than ArrayList of the
struct because of boxing
Jan 31 '06 #4
There is; when you put something into an ArrayList, its up cast to
object when its added, and has to be down cast when you pull it out.
That takes time. Worse, value types have to be boxed and unboxed,
adding even more time. A generic collection won't have these problems
(unless as someone else mentioned, you have a generic collection of
objects).

Jan 31 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by mark | last post: by
10 posts views Thread by Ruediger Klaehn | last post: by
2 posts views Thread by Marc | last post: by
6 posts views Thread by nick_nw | last post: by
3 posts views Thread by Showjumper | last post: by
4 posts views Thread by SHEBERT | last post: by
7 posts views Thread by SpotNet | last post: by
7 posts views Thread by =?Utf-8?B?Q29kZVJhem9y?= | last post: by
reply views Thread by rosydwin | last post: by

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.