다음을 통해 공유


TypeOf 연산자(Visual Basic)

식 결과의 런타임 형식이 지정된 형식과 형식과 호환되는지 여부를 확인합니다.

문법

result = TypeOf objectexpression Is typename  
result = TypeOf objectexpression IsNot typename  

부분

result
반환. Boolean 값입니다.

objectexpression
필수 사항입니다. 참조 형식으로 계산되는 식입니다.

typename
필수 사항입니다. 모든 데이터 형식 이름입니다.

비고

연산자는 TypeOf 런타임 형식 objectexpression 이 .와 typename호환되는지 여부를 확인합니다. 호환성은 의 형식 범주 typename에 따라 달라집니다. 다음 표에서는 호환성을 결정하는 방법을 보여줍니다.

의 형식 범주 typename 호환성 조건
클래스 objectexpression 가 형식이거나 상속되는 형식 typename 입니다. typename
구조 objectexpression 형식이 typename
인터페이스 objectexpression 구현하는 typename 클래스에서 구현하거나 상속합니다. typename

런타임 형식 objectexpression 이 호환성 조건을 result 충족하는 경우는 다음과 같습니다 True. 그렇지 않으면 resultFalse입니다. nullTypeOf이면 objectexpression ...Is가 반환False되고 ...IsNotTrue

TypeOf는 항상 ... 식을 생성 TypeOfIs 하기 위해 키워드와 함께 Is 사용되거나 ...IsNot 식을 생성하는 TypeOf키워드와 함께 IsNot 사용됩니다.

예시

다음 예제에서는 ...Is 식을 사용하여 TypeOf다양한 데이터 형식을 사용하는 두 개체 참조 변수의 형식 호환성을 테스트합니다.

Dim refInteger As Object = 2
MsgBox("TypeOf Object[Integer] Is Integer? " & TypeOf refInteger Is Integer)
MsgBox("TypeOf Object[Integer] Is Double? " & TypeOf refInteger Is Double)
Dim refForm As Object = New System.Windows.Forms.Form
MsgBox("TypeOf Object[Form] Is Form? " & TypeOf refForm Is System.Windows.Forms.Form)
MsgBox("TypeOf Object[Form] Is Label? " & TypeOf refForm Is System.Windows.Forms.Label)
MsgBox("TypeOf Object[Form] Is Control? " & TypeOf refForm Is System.Windows.Forms.Control)
MsgBox("TypeOf Object[Form] Is IComponent? " & TypeOf refForm Is System.ComponentModel.IComponent)

변수 refInteger 의 런타임 형식은 .입니다 Integer. 호환되지만 .와 호환 IntegerDouble되지 않습니다. 변수 refForm 의 런타임 형식은 .입니다 Form. 이 형식은 Form 해당 형식 Control 이기 때문에 호환됩니다. 이는 상속되기 Control때문 Form 이며IComponent, 구현되는 형식에서 Component상속되기 때문 Form 입니다IComponent. 그러나 . refFormLabel

참고하십시오