Using typeof operator in if statement : typeof « Operator « C# / CSharp Tutorial






using System;
using System.Collections.Generic;
using System.Text;

class MainClass
{
    static void Main(string[] args)
    {
        SomeClass someObject = new SomeClass();

        if (someObject.GetType() == typeof(SomeClass))
        {
            Console.WriteLine("We have a SomeClass object here");
        }

    }
}

class SomeClass
{
}
We have a SomeClass object here








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