Solved

getting the type of an object c#

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
Reference issues in Visual Studio 3 41
SqlDependency to get update from sql to my c# app 2 67
VB.NET 2008 - SQL Timeout 9 34
Name Space error VS2015 1 27
In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

820 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