The first, my code as below:
Dim eventType As Object = Nothing
eventType = GetEventType()
If Not (eventType Is Nothing) Then
If TypeOf eventType Is ClassSelectEvents Then
m_selectEvents = eventType ' Warning BC 42016: Implicit type conversion from 'Object' to 'ClassSelectEvents'.
End If
If TypeOf eventType Is ClassMouseEvents Then
m_mouseEvents = eventType ' Warning BC 42016: Implicit type conversion from 'Object' to 'ClassMouseEvents'.
End If
If TypeOf eventType Is ClassTriadEvents Then
m_triadEvents = eventType ' Warning BC 42016: Implicit type conversion from 'Object' to 'ClassTriadEvents'.
End If
End If
Because of the warning display after the compiler, I modified it as shown below but still displayed a warning.
At the second If statement, i think type of eventType
is Object
. Is that different? My code where is wrong Please tell me how hide warnings ?
Thanks in advance.
Dim eventType As Object = Nothing
eventType = GetEventType()
If Not (eventType Is Nothing) Then
If TypeOf eventType Is ClassSelectEvents Then
'm_selectEvents = eventType
'm_selectEvents = TryCast(eventType, ClassSelectEvents)
m_selectEvents = DirectCast(eventType, ClassSelectEvents)
End If
If TypeOf eventType Is ClassMouseEvents Then
'm_mouseEvents = eventType
'm_selectEvents = TryCast(eventType, ClassMouseEvents) ' Warning BC42016: Implicit type conversion from 'ClassMouseEvents' to 'ClassSelectEvents'.
m_selectEvents = DirectCast(eventType, ClassMouseEvents) ' Warning BC42016: Implicit type conversion from 'ClassMouseEvents' to 'ClassSelectEvents'.
End If
If TypeOf eventType Is ClassTriadEvents Then
'm_triadEvents = eventType
'm_selectEvents = TryCast(eventType, ClassTriadEvents) ' Warning BC42016: Implicit type conversion from 'ClassTriadEvents' to 'ClassSelectEvents'.
m_selectEvents = DirectCast(eventType, ClassTriadEvents) ' Warning BC42016: Implicit type conversion from 'ClassTriadEvents' to 'ClassSelectEvents'.
End If
End If