Show/Hide Toolbars

XSharp

 

In .Net, all types are inherited from the System.Type.

 

Syntax

TypeOf( type )

 

The TypeOf operator gets the System.Type of a type.

This code sample shows the use case of typeof operator using C#.

 

Console.WriteLine(typeof(String))    
Console.WriteLine(typeof(USUAL))

The following example demonstrates several ways to obtain a type

Example

FUNCTION Start() AS VOID
LOCAL t1 AS Type
LOCAL t2 AS Type
LOCAL t3 AS Type
LOCAL t4 AS Type
LOCAL s AS STRING
s := "Live long and prosper!"
t1 := s:GetType()
t2 := typeof(System.String)
t3 := typeof(STRING)
t4 := Type.GetType( "System.String" )
? "Type objects are equal:", t1 == t2 .and. t1 == t3 .and. t1 == t4
? t1:Name
? t1:FullName
? t1:AssemblyQualifiedName
RETURN

Note

_typeof() (with a leading underscore and parenthesis) is also supported for compatibility with Visual Objects and is synonymous with sizeof.