.NETGURU
NodeType values in C# vs. in VB.NET
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngxml' list.


Thomas Stone
Hi,

I am confused about this...

When I am writing in VB.NET and access the NodeType property of an XmlNode
object, I get back a number such as 1 for elements, or 2 for attributes, or
3 for text nodes (similar to working with NodeType properties in MSXML's
DOM implementation for instance).

But when I do the exact same thing in C#, I get back the name instead:
Element, Attribute, Text, and so on.

Why would these be different in the two languages?

Also, because these are enumeration values, I know I can use ToString() to
convert the numbers to the names, when using VB.NET. But what if I want to
get the numbers and I am working in C#? Is there a method or something I
can use to go that way, from the provided NodeType name to its enumeration
number?

Thanks,

Tom S.

Reply to this message...
 
    
Dan Wahlin
You can do something like the following (C# shown) to convert a string
back to an enumeration:

deviceCategory =
(DeviceTypesEnum)TypeDescriptor.GetConverter(typeof(DeviceTypesEnum)).Co
nvertFromString(stringValue);

You'll need to reference the System.ComponentModel namespace. However,
instead of worrying about that why not just use the enumeration value in
the first place (for both C# and VB.NET) when checking node types (if
(node.NodeType == XmlNodeType.Element)...., etc.)?

Dan Wahlin

Wahlin Consulting LLC
Microsoft MVP - ASP.NET
http://www.XMLforASP.Net: #1 ASP.NET XML Resource
XML for ASP.NET Developers by Dan Wahlin in bookstores everywhere!

-----Original Message-----
From: Thomas Stone [mailto:Click here to reveal e-mail address]
Sent: Thursday, July 11, 2002 11:11 AM
To: aspngxml
Subject: [aspngxml] NodeType values in C# vs. in VB.NET

Hi,

I am confused about this...

When I am writing in VB.NET and access the NodeType property of an
XmlNode
object, I get back a number such as 1 for elements, or 2 for attributes,
or
3 for text nodes (similar to working with NodeType properties in MSXML's

DOM implementation for instance).

But when I do the exact same thing in C#, I get back the name instead:
Element, Attribute, Text, and so on.

Why would these be different in the two languages?

Also, because these are enumeration values, I know I can use ToString()
to
convert the numbers to the names, when using VB.NET. But what if I want
to
get the numbers and I am working in C#? Is there a method or something I

can use to go that way, from the provided NodeType name to its
enumeration
number?

Thanks,

Tom S.

| [aspngxml] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngxml.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

Reply to this message...
 
    
Joel Mueller
Or if you want to get the integer value of an enumeration, just cast it
to an int:

int foo = (int)node.NodeType;

[Original message clipped]

Reply to this message...
 
 
System.ComponentModel.TypeDescriptor
System.Xml.XmlNode
System.Xml.XmlNodeType




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification