Type Class in C#

In this blog I am trying to explain the concept of Type Class in C#.

Type Class

The C# typeof operator returns a Type object. A Type object that represents a type is unique; that is, two Type object references refer to the same object if and only if they represent the same type. Represents type declarations: class types, interface types, array types, value types, enumeration types, type parameters, generic type definitions, and open or closed constructed generic types. This allows for comparison of Type objects using reference equality. Type is the root of the System.Reflection functionality and is the primary way to access metadata. Use the members of Type to get information about a type declaration, such as the constructors, methods, fields, properties, and events of a class, as well as the module and the assembly in which the class is deployed.

Example: -

using System;

using System.Reflection;

class ExampleType


    static void Main(string[] args)


        Type task = typeof(String);

        MethodInfo substr = task.GetMethod("Substring", new Type[] { typeof(int), typeof(int) });

        Object result = substr.Invoke("Hello, mindstick!", new Object[] { 7, 9 });

        Console.WriteLine("{0} returned \"{1}\".", substr, result);





Output: -

Leave Comment