Can I get the name of a type at runtime?

Yes, use the GetType method of the object class (which all types inherit from). For example:
using System;

class CTest
{
class CApp
{
public static void Main()
{
long i = 10;
CTest ctest = new CTest();

DisplayTypeInfo( ctest );
DisplayTypeInfo( i );
}

static void DisplayTypeInfo( object obj )
{
Console.WriteLine( "Type name = {0}, full type name = {1}", obj.GetType(), obj.GetType().FullName );
}
}
}

produces the following output:

Type name = CTest, full type name = CTest
Type name = Int64, full type name = System.Int64

Comments

Popular posts from this blog

How do I calculate a MD5 hash from a string?

What is WSDL?