CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2004
    Posts
    23

    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

  2. #2
    Join Date
    Apr 2004
    Location
    England, Europe
    Posts
    2,492

    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
    My hobby projects:
    www.rclsoftware.org.uk

  3. #3
    Join Date
    Feb 2005
    Location
    Israel
    Posts
    1,475

    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();

  4. #4
    Join Date
    Mar 2004
    Posts
    23

    Re: C# beginner question on collections

    Thank you! Both helped me out!

    Bye,
    Scapin

  5. #5
    Join Date
    Nov 2006
    Location
    North Bend, WA
    Posts
    487

    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
  •  





Click Here to Expand Forum to Full Width

Featured