Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to create collection class in C#

How to create collection class in C#

Scheduled Pinned Locked Moved C#
csharpalgorithmstutorial
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Chiman1
    wrote on last edited by
    #1

    I have created a collection class which has below methods

    Class EmPInfo
    {
    Count()
    Add (Struct classinfo)
    Item()
    Sort()
    }

    This class uses List<> object ,which holdes Emp class obj. Add method internally craetes a EMP class object and stores that data in a list object. Sort function perform sorting using some information set by the user. Please suggest the correct way of creating a colletion class in .Net.

    D L 3 Replies Last reply
    0
    • C Chiman1

      I have created a collection class which has below methods

      Class EmPInfo
      {
      Count()
      Add (Struct classinfo)
      Item()
      Sort()
      }

      This class uses List<> object ,which holdes Emp class obj. Add method internally craetes a EMP class object and stores that data in a list object. Sort function perform sorting using some information set by the user. Please suggest the correct way of creating a colletion class in .Net.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      I'm confused - you already have your answer (you gave it yourself) but you're still asking how to do it?

      1 Reply Last reply
      0
      • C Chiman1

        I have created a collection class which has below methods

        Class EmPInfo
        {
        Count()
        Add (Struct classinfo)
        Item()
        Sort()
        }

        This class uses List<> object ,which holdes Emp class obj. Add method internally craetes a EMP class object and stores that data in a list object. Sort function perform sorting using some information set by the user. Please suggest the correct way of creating a colletion class in .Net.

        D Offline
        D Offline
        DaveyM69
        wrote on last edited by
        #3

        Implement ICollection<T> and wrap your list or derive from List<T>

        Dave

        If this helped, please vote & accept answer!

        Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
        BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

        1 Reply Last reply
        0
        • C Chiman1

          I have created a collection class which has below methods

          Class EmPInfo
          {
          Count()
          Add (Struct classinfo)
          Item()
          Sort()
          }

          This class uses List<> object ,which holdes Emp class obj. Add method internally craetes a EMP class object and stores that data in a list object. Sort function perform sorting using some information set by the user. Please suggest the correct way of creating a colletion class in .Net.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          http://msdn.microsoft.com/en-us/library/system.collections.collectionbase.aspx[^]

          D 1 Reply Last reply
          0
          • L Lost User

            http://msdn.microsoft.com/en-us/library/system.collections.collectionbase.aspx[^]

            D Offline
            D Offline
            DaveyM69
            wrote on last edited by
            #5

            Since v2.0 this is not the recommended way due to the boxing/unboxing expense (an ArrayList which holds objects is used for the InnerList). Instead you should use System.Collections.ObjectModel.Collection<T>[^].

            Dave

            If this helped, please vote & accept answer!

            Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
            BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups