Using typeof operator in if statement : Typeof : Operator C# Examples


C# Examples » Operator » Typeof »

 

Using typeof operator in if statement









    
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
{
}
    
   
  
   



Output

We have a SomeClass object here


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Operator
» Typeof