Operators: classof

classof operator.

Syntax

classofobject‑operand

Discussion

The classof operator determines the class of the object specified in the object operand right to the operator. The knowledge about the class of an object is useful when you intend to dynamically create new instances of exactly the same class. With the classof operator you can also verify, whether two objects are of the same class. Please note, using the operator with a null object as operand, will result in a null class. For example:

var object o1 = SomeView; // Some, not exactly specified object
var object o2 = null;

var class  result1 = classof o1;  // Identifies the class of 'o1'
var class  result2 = classof o2;  // result2 = null

// Create a new instance of the original class of the 'o1' object
var object o3 = new result1;

// Yes, the objects 'o1' and 'o3' are of the same class.
var bool  result = classof o1 == classof o3; // result = true