[RESOLVED] [02/03] Checking type
I've got a mustinherit class with two subclasses.
Lets say the class is "Shape" and the subclasses are "Circle" and "Triangle"
Now I've got an array of shapes containing both circles and triangles.
How can I check which type the item is?
I noticed that this doesn't work:
VB Code:
if array(i).getType.equals(Shape) then
end if
But this does:
VB Code:
dim s as Shape
...
if array(i).getType.equals(s.getType) then
end if
It seems stupid to me that I should create a variable of the type, so isn't there a better way?
Re: [02/03] Checking type
You can use "TypeOf", an example is below:
VB Code:
Dim MyArray As New ArrayList
MyArray.Add("This")
MyArray.Add(3)
For Each obj As Object In MyArray
If TypeOf obj Is String Then
MessageBox.Show("Its a string type!")
End If
If TypeOf obj Is Integer Then
MessageBox.Show("Its an integer!")
End If
Next
Re: [02/03] Checking type
Ah yes, that was the thing I was looking for.
Thanks.