How to create collection class in C#
-
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.
-
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.
-
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.
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) -
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.
-
Since v2.0 this is not the recommended way due to the boxing/unboxing expense (an
ArrayList
which holdsobject
s is used for theInnerList
). 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)