Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

getting the type of an object c#

Posted on 2009-05-20
3
Medium Priority
?
611 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 2000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Integration Management Part 2
Suggested Courses

926 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