|
typeof (alternately typeOf or TypeOf) is an operator provided by several programming languages which determines the data type of a given variable. This can be useful when constructing parts of programs that need to accept many types of data but may need to take different action depending on the type of data provided. In languages that support polymorphism and type casting, the typeof operator can have one of two distinct meanings when applied to an object. In some languages, such as Visual Basic,〔https://msdn.microsoft.com/en-us/library/0ec5kw18(VS.80).aspx "TypeOf Operator (Visual Basic)" in MSDN〕 the typeof operator returns the dynamic type of the object. That is, it tells the program what the true, original type of the object is, irrespective of any type casting. In these languages, the typeof operator is the method for obtaining run-time type information. In other languages, such as C#〔https://msdn.microsoft.com/en-us/library/58918ffs(VS.80).aspx "typeof (C#)" in MSDN〕 or D〔http://digitalmars.com/d/1.0/declaration.html#Typeof〕 and some nonstandard extensions to C and C++,〔http://gcc.gnu.org/onlinedocs/gcc/Typeof.html "Typeof" in Using the GNU Compiler Collection〕 the typeof operator returns the static type of the object. That is, it tells the program what type the object is declared to be at that point in the program, irrespective of its original form. These languages usually have other constructs for obtaining run-time type information, such as typeid. ==Examples== * In the C programming language, the GCC extension provides typeof (copied from 〔). * In C#: * In VB.NET The C# variant of "typeof" should be translated into the VB.NET's ''GetType'' method. TypeOf keyword in VB.NET is used to compare an object reference variable to a data type. The following example uses TypeOf...Is expressions to test the type compatibility of two object reference variables with various data types. * In JavaScript: 抄文引用元・出典: フリー百科事典『 ウィキペディア(Wikipedia)』 ■ウィキペディアで「Typeof」の詳細全文を読む スポンサード リンク
|