상위 질문
타임라인
채팅
관점

Typeof

위키백과, 무료 백과사전

Remove ads

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' );
}

타입스크립트:[1]

function (param: typeof existingObject) { ... }
let newObject: typeof existingObject;
Remove ads

같이 보기

  • sizeof

각주

Loading related searches...

Wikiwand - on

Seamless Wikipedia browsing. On steroids.

Remove ads