-
January 23rd, 2007, 06:23 AM
#1
C# beginner question on collections
Hi there,
I am a Visual C++ developer and I now have to write something in C# for a project.
My question is about objects and object arrays. In C++ i used CObject and CObArrays for this. My objects were derived from CObject and I used a CObArray to hold them.
What classes can I use for this in C#.net ? I need a collection class for iterating, insertion and deletion of objects etc.
Do you have any hint. I find the MSDN not very helpful with this one unfortunately.
Thanks a lot,
scapin
-
January 23rd, 2007, 07:56 AM
#2
Re: C# beginner question on collections
Have a look at the treeviews on the lefthand side of the following webpages:
System.Collections Namespace
and
System.Collections.Generic Namespace
-
January 23rd, 2007, 08:32 AM
#3
Re: C# beginner question on collections
For array of objects you should use ArrayList.
If you want a typed collection (a collection of a specific type), use the generic List<YourType>.
Each object in C# inherits from Object class.
Each of the options gives you automatic insertion and deletion.
You can iterate by using the foreach statement:
Code:
foreach (YourType obj in yourCollection)
obj.DoSomething();
-
January 23rd, 2007, 09:40 AM
#4
Re: C# beginner question on collections
Thank you! Both helped me out!
Bye,
Scapin
-
January 23rd, 2007, 09:59 AM
#5
Re: C# beginner question on collections
Unless you really need to have different types of objects in your collections, you are better off using generics whenever possible. It makes things so much easier to deal with.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|