K
kevinwolfe
Hello all,
I have a class which inherits 'Collection' and I use this class to
store different data types. I'd like to have a method inside the class
that does the following:
For Each obj As Object In new_linked_collection
Me.DoSomething(obj)
Next
where DoSomething is overloaded for each of the different data types
I'm storing in the collection. The problem is, as I've defined obj as
an Object, visual basic craps a brick unless I recast obj to a
particlar type, such as
For Each obj As Object In new_linked_collection
If (obj.GetType.ToString.Equals("MyProgram.MyDataType1"))
Then
Dim castedObj As MyDataType1 = obj
Me.DoSomething(castedObj)
Else
Dim castedObj As MyDataType2 = obj
Me.DoSomething(castedObj)
End If
Next
There has to be a more elegate way of doing this (expecially as I have
more than 2 different data types stored in the collection). Any
suggestions?
Thanks a bunch,
Kevin
I have a class which inherits 'Collection' and I use this class to
store different data types. I'd like to have a method inside the class
that does the following:
For Each obj As Object In new_linked_collection
Me.DoSomething(obj)
Next
where DoSomething is overloaded for each of the different data types
I'm storing in the collection. The problem is, as I've defined obj as
an Object, visual basic craps a brick unless I recast obj to a
particlar type, such as
For Each obj As Object In new_linked_collection
If (obj.GetType.ToString.Equals("MyProgram.MyDataType1"))
Then
Dim castedObj As MyDataType1 = obj
Me.DoSomething(castedObj)
Else
Dim castedObj As MyDataType2 = obj
Me.DoSomething(castedObj)
End If
Next
There has to be a more elegate way of doing this (expecially as I have
more than 2 different data types stored in the collection). Any
suggestions?
Thanks a bunch,
Kevin