Solved

getting the type of an object c#

Posted on 2009-05-20
3
573 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

816 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

11 Experts available now in Live!

Get 1:1 Help Now