typeof a Class name : typeof « Operator « C# / CSharp Tutorial






using System;
using System.IO;

class MainClass
{
    public static void Main() 
    {
        Object someObject = new StringReader("This is a StringReader");

        if (typeof(StringReader) == someObject.GetType()) 
        {
            Console.WriteLine("typeof: someObject is a StringReader");
        }

    }
}
typeof: someObject is a StringReader








3.16.typeof
3.16.1.Using typeof
3.16.2.Demonstrate typeof
3.16.3.typeof a Class name
3.16.4.Using typeof operator in if statement
3.16.5.Obtain type information using the typeof operator
3.16.6.Assign returning value from 'Typeof Operator' to 'Type' variable