|
-
Jun 28th, 2006, 11:05 AM
#1
Thread Starter
Lively Member
[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?
-
Jun 28th, 2006, 11:58 AM
#2
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
-
Jun 28th, 2006, 12:06 PM
#3
Thread Starter
Lively Member
Re: [02/03] Checking type
Ah yes, that was the thing I was looking for.
Thanks.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|