Solved

getting the type of an object c#

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

757 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

22 Experts available now in Live!

Get 1:1 Help Now