Generic Collections In vb.net 2005 Help

Hi,
Getting to grasp with Generics.Could somebody help as follows:

In vs 2003 I used to write strongly typed collections now I could simplify it all with generic.
I am trying to write some base collections

What is the difference between inheriting from collectionbase and list?

I have tried to implement the IEnumerator in my collection but the for each still doesnt work?
Can somebody provide a good example of collections using generics implementing Ienumerator,and explaining the diff between List and collectionBase?
Possibly in vb.net 2005 beta 2
Also some example of dictionary could help

thanks a lot

[635 byte] By [vbjunkie] at [2008-1-12]
# 1
System.Collections.CollectionBase is similar to System.Collections.ObjectModel.Collection(Of T)

and

System.Collections.ArrayList is similar to System.Collections.Generic.List(Of T).

You probably want to use the Collection(Of T) class. The different between that and CollectionBase, is that Collection(Of T) class allows you provide your own storage for the collection in the constructor, whereas the CollectionBase always uses an ArrayList.

It is easy to inherit the Collection(Of T):

Public Class MyObjectCollection
Inherits Collection(Of MyObject)

End Class

Then to use:

Dim collection As New MyObjectCollection()

Collection(Of T) already does the hard work for you and implements IList(Of T), ICollection(Of T), IEnumerable(Of T), IList, ICollection and IEnumerable.

DavidM.Kean at 2007-8-21 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 2
First Of all Thanks for your reply.
There is hardly any info whatsoever in the matter on vb.net .All in c# and things sometimes are done differently.

To make sure I understand
If I Inherit from Collection (of t) then I don't have to worry about implementing IEnumerable. Correct?I dont even have to have a method like "GetEnumerator"
So when do you have to implement the IEnumerator?in the List one?

if i want to enhance the collection I could do:

=========
Imports system.Collection.ObjectModel

Public Class MyCollectionBase(0f t)
inherits Collection(0f t)

''//no need of implementing IEnumerable.For each taken care of already.

end class
============

Would I ask too much if you could provide an example of a collection you use that implements some additional functionalities like Sorting,Filtering ,find etc .
Cannot find examples and it's driving me mad.
Thanks again for your reply.

vbjunkie at 2007-8-21 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 3
You don't have implement IEnumerable as Collection(Of T) already does it. And you don't need a class that IEnumerator as Collection(Of T) already worries about that.

That's not saying that you can't implement those methods again if you want different implementations than the default, its just means that Collection(Of T) already does quite a lot.

To implement sorting is easy, do the following:

Public Class MyObjectCollection
Inherits Collection<MyObject>

Public ReadOnly Property InnerList As List<MyObject>
Get
Return CType
(List,List<MyObject>Wink
End Get
End Property

Public Sub Sort(ByVal comparer As IComparer)
InnerList.Sort(comparer)
End Sub

Public Class MyObjectCollection
End Class
End Class

DavidM.Kean at 2007-8-21 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 4
Thanks a lot for your help .
You have clarified lots of doubts I had.

I wish there was more info on vb.net 2005 especially on generics and what you can do with it.
Thanks again

vbjunkie at 2007-8-21 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 5

If those two posts answered your questions, can you click the 'mark as correct answer' so that other users will be helped by them.

Update: whoops, just noticed that you had already done that for the first one. Wink

DavidM.Kean at 2007-8-21 > top of Msdn Tech,Visual Basic,Visual Basic Language...