Information Technology Reference
In-Depth Information
The output of this code is the following:
Field : Field1
Field : Field2
Method: Method1
Method: Method2
Method: GetType
Method: ToString
Method: Equals
Method: GetHashCode
The
typeof
operator is also called by the
GetType
method, which is available for every
object of every type. For example, the following code retrieves the name of the type of
the object:
class SomeClass
{
...
}
class Program
{
static void Main()
{
SomeClass s = new SomeClass();
Console.WriteLine("Type s: {0}", s.GetType().Name);
}
}
This code produces the following output:
Type s: SomeClass