I'm not quite sure how to explain why I want to do this without going into a long-winded explanation, so I'll just skip that bit.
I'm wondering if anyone can help me out with some code to determine object type - essentially, I've got an object that may be an instance of one of two types, and I'd like to test which it is, but I can't for the life of me work out how!
Well, you get the idea, this is what I'd like to do, but this code doesn't work ("'Class1' is a type and cannot be used as an expression"), but I can't find out how I should do it!
Do be honest, I'm struggling a bit find search terms to put into Google to help me out.
If anyone could point me in the right direction it would be much appreciated!
Cheers,
Dan.
I'm wondering if anyone can help me out with some code to determine object type - essentially, I've got an object that may be an instance of one of two types, and I'd like to test which it is, but I can't for the life of me work out how!
Code:
Dim obj As Object = New Class1
If (obj Is Class1) Then
MsgBox("Object is of type Class1")
ElseIf (obj Is Class2) Then
MsgBox("Object is of type Class2")
Else
MsgBox("Don't know!")
End If
Well, you get the idea, this is what I'd like to do, but this code doesn't work ("'Class1' is a type and cannot be used as an expression"), but I can't find out how I should do it!
Do be honest, I'm struggling a bit find search terms to put into Google to help me out.
If anyone could point me in the right direction it would be much appreciated!
Cheers,
Dan.