Solved

getting the type of an object c#

Posted on 2009-05-20
3
565 Views
Last Modified: 2012-06-27
Hi
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

0
Comment
Question by:peter3244
  • 2
3 Comments
 
LVL 11

Accepted Solution

by:
saragani earned 500 total points
ID: 24431058
You are not far from it.... you almost got it right...

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


0
 
LVL 11

Expert Comment

by:saragani
ID: 24431101
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");
0
 

Author Closing Comment

by:peter3244
ID: 31583466
Thanks, nice and simple!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Entity Framework Error: 'The user instance login flag is not supported' 12 32
Class object 2 27
Resolve Dependency Issues 4 47
Reset asp.net login password 4 34
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now