Typeof
typeof(타입오브), typeOf, TypeOf는 여러 프로그래밍 언어에서 변수의 자료형을 알아내기 위해 제공하는 연산자이다. 자료형을 명시적으로 지정하지 않고 데이터의 여러 유형을 수용해야 하는 프로그램들을 구성할 때 유용하다.
예시
C (프로그래밍 언어)의 비표준(GNU) 확장에서 typeof는 두 변수의 최대 값을 결정할 목적으로 일반 매크로를 정의하기 위해 사용할 수 있다:
#define max(a,b) ({ typeof (a) _a = (a); typeof (b) _b = (b); _a > _b ? _a : _b; })
C 샤프:
// Given an object, returns if it is an integer.
// The "is" operator can be also used to determine this.
public static bool IsInteger(object o) {
return ( o.GetType() == typeof(int) );
}
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)
function isNumber(n)
{
return ( typeof n === 'number' );
}
function (param: typeof existingObject) { ... }
let newObject: typeof existingObject;
같이 보기
각주
- ↑ “Using `typeof` to infer a type” (영어). 《Learn TypeScript》. 2022년 1월 28일에 확인함.
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.