getting the type of an object c#

I'm writing code in C#

basically i have an object and I want to check whether its an XmlNode or not

object myobject = processIt();
//Bit I'm unclear about
//have written statement as pseudo code...
if (myobject is "XmlNode")
    MessageBox.Show("Its an xmlNode");

Open in new window

Who is Participating?
saraganiConnect With a Mentor Commented:
You are not far from it.... you almost got it right...

if (myobject is XmlNode)
    MessageBox.Show("Its an xmlNode");

Few other options are:

if (myobject .GetType() == typeof(XmlNode))
    MessageBox.Show("Its an xmlNode");

XmlNode xmlNode = myobject  as XmlNode;

if (xmlNode != null)
    MessageBox.Show("Its an xmlNode");
peter3244Author Commented:
Thanks, nice and simple!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.