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

Generic Collections In vb.net 2005 Help
Ejan
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.
XBTester
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
eajam
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 MyObjectCollectionInherits Collection(Of MyObject)
End ClassThen 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.
Ilya Lehrman
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>
End Get
End Property
Public Sub Sort(ByVal comparer As IComparer)
InnerList.Sort(comparer)
End Sub
Public Class MyObjectCollection
End Class
End Class
Jeffrey Litch
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.