473,394 Members | 2,071 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,394 software developers and data experts.

collection classes

I'm pretty new to OOP and I'm just starting looking at generics and
collection classes. I understand why I might want to create a business
class, but can somebody please explain to me the reasons behind creating
collection classes?
Many thanks,

Mike

*** Sent via Developersdex http://www.developersdex.com ***
Mar 19 '07 #1
8 1538
Mike P wrote:
I'm pretty new to OOP and I'm just starting looking at generics and
collection classes. I understand why I might want to create a business
class, but can somebody please explain to me the reasons behind creating
collection classes?
With .NET 2.0 and generics you will probably not need to create
collection classes - just use them.

You need them whenever you have more than one.

Arne
Mar 19 '07 #2
Collection classes get pretty advanced so I wouldn't worry too much
about it for now. A lot of .Net uses ICollection members without you
even knowing it. For instance the foreach loop is built around
IEnumerable, IEnumerable classes can be automatically serialized (with
no extra code on your part). As far as generics look at
http://msdn.microsoft.com/library/de...p_generics.asp

-James

Mar 19 '07 #3

If you just need a list of business objects, then
List < myobject newList = new List < myobject ();

would suffice.

however, sometimes you want to have the collection have its own
functionality.
therefore

MyObjectCollection : List <myobject>

is appropriate.

and you can tack on methods there.
Here is an interesting implementation:

http://www.mattberther.com/?p=592


"Mike P" <mi*******@gmail.comwrote in message
news:uS**************@TK2MSFTNGP05.phx.gbl...
I'm pretty new to OOP and I'm just starting looking at generics and
collection classes. I understand why I might want to create a business
class, but can somebody please explain to me the reasons behind creating
collection classes?
Many thanks,

Mike

*** Sent via Developersdex http://www.developersdex.com ***

Mar 19 '07 #4
On Mar 19, 12:20 pm, Mike P <mike.p...@gmail.comwrote:
I'm pretty new to OOP and I'm just starting looking at generics and
collection classes. I understand why I might want to create a business
class, but can somebody please explain to me the reasons behind creating
collection classes?

Many thanks,

Mike

*** Sent via Developersdexhttp://www.developersdex.com***
You may want to create a custom collection class if there are
operations that make sense to exist on a collection of a specific
type. Since you can't add properties or methods to an existing class
you'll have to subclass or create a brand new class. For example, if
you have an Account business entity then it might make sense to have
an AccountCollection class where you could define a TotalBalance
property that would return the net balance of all contained accounts.

In the pre 2.0 days it was common to create a custom collection to
strongly type its contained items. But, with generics that's no
longer necessary.
Mar 19 '07 #5
What uses are there for generics? Are they only used with collection
classes?
*** Sent via Developersdex http://www.developersdex.com ***
Mar 20 '07 #6
On Mar 20, 9:08 am, Mike P <mike.p...@gmail.comwrote:
What uses are there for generics? Are they only used with collection
classes?
Collections are the principal use, but not the only use. They're
useful wherever you want to enforce type-safety at the caller of the
class, but the class itself doesn't need to know what type is involved
(or is able to express the constraints in a generic way).

Jon

Mar 20 '07 #7
On Mar 20, 5:08 am, Mike P <mike.p...@gmail.comwrote:
What uses are there for generics? Are they only used with collection
classes?

*** Sent via Developersdexhttp://www.developersdex.com***
Generics are also faster because there is no boxing to and from object

Mar 20 '07 #8
james <ja********@gmail.comwrote:
On Mar 20, 5:08 am, Mike P <mike.p...@gmail.comwrote:
What uses are there for generics? Are they only used with collection
classes?

Generics are also faster because there is no boxing to and from object
Note that that only applies for value types.

--
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
Mar 20 '07 #9

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

Similar topics

24
by: downwitch | last post by:
Hi, I know this has been covered here and in the .public groups, but it seems like it's been a while, especially around here, so I just thought I'd ask again to see if anyone has figured out a...
11
by: Pavils Jurjans | last post by:
Hello, There's some confusion about the purpose and difference between these handy classes... First, both of them are holding number of key - value pairs, right? Then, I see that there may be...
2
by: Robert W. | last post by:
I'm trying to write a utility that will use Reflection to examine any data model I pass it and correctly map out this model into a tree structure. When I say "any" , in fact there will only be 3...
2
by: Edward Diener | last post by:
In C++ an overridden virtual function in a derived class must have the exact same signature of the function which is overridden in the base class, except for the return type which may return a...
2
by: Brian | last post by:
NOTE ALSO POSTED IN microsoft.public.dotnet.framework.aspnet.buildingcontrols I have solved most of my Server Control Collection property issues. I wrote an HTML page that describes all of the...
16
by: Ben Hannon | last post by:
Hi, I'm writting a COM Class in VB.NET to be used in a VB6 project (Tired of the VB6 hassles with cloning and serializing an object). All my classes I need cloneable/serializable are now in a...
4
by: Andrew | last post by:
I need to have a series of collection classes that inherit (I think) from each other. What is the best way to do this in .NET? In VB6 I had a series of collection classes each passing a reference...
3
by: Dave | last post by:
Please - anyone that can help. I am getting confusing results while trying to expose a collection from a web service. I have a webservice in which a web method accepts a collection as a...
19
by: Jamey Shuemaker | last post by:
I'm in the process of expanding my knowledge and use of Class Modules. I've perused MSDN and this and other sites, and I'm pretty comfortable with my understanding of Class Modules with the...
7
by: =?Utf-8?B?Q29kZVJhem9y?= | last post by:
Can someone explain a few things about collections to me. In C# 2 generics, you can create a collection class by inheriting from System.Collections.ObjectModel.Collection. Using this you can...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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,...
0
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 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.