471,082 Members | 719 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,082 software developers and data experts.

XMLNode

In VB.Net, the following declaration builds and executes with no exceptions:

Dim XMLDoc As New XmlDocument
Dim Node As XmlNode

But in C#, the following (equivalent?!) returns the build error "XMLNode
does not exist in the current context.":

XmlDocument XMLDoc = new XmlDocument();
XmlNode Node = XMLNode;
Aug 2 '06 #1
3 2743
Earl wrote:
In VB.Net, the following declaration builds and executes with no exceptions:

Dim XMLDoc As New XmlDocument
Dim Node As XmlNode

But in C#, the following (equivalent?!) returns the build error "XMLNode
does not exist in the current context.":

XmlDocument XMLDoc = new XmlDocument();
XmlNode Node = XMLNode;
Just do:

XmlDocument XMLDoc = new XmlDocument();
XmlNode Node;

You're just declaring the variable, without initializing it at all.

Jon

Aug 2 '06 #2
Earl wrote:
In VB.Net, the following declaration builds and executes with no exceptions:

Dim XMLDoc As New XmlDocument
Dim Node As XmlNode

But in C#, the following (equivalent?!) returns the build error "XMLNode
does not exist in the current context.":

XmlDocument XMLDoc = new XmlDocument();
XmlNode Node = XMLNode;
Your translation is awry. You have the first line right: the translation of

Dim variable_name As New type_for_variable

(a declaration and and assignment in one) is indeed

type_for_variable variable_name = new type_for_variable();

, and is in fact one of the rare cases where VB uses fewer characters
than C#. But where VB does a simple declaration:

Dim variable_name As type_for_variable

without actually assigning any value to variable_name, the C# maintains
its usual terseness-advantage:

type_for_variable variable_name;
--
Larry Lard
la*******@googlemail.com
The address is real, but unread - please reply to the group
For VB and C# questions - tell us which version
Aug 3 '06 #3
Thanks to both you and Jon.

"Larry Lard" <la*******@googlemail.comwrote in message
news:4j************@individual.net...
Earl wrote:
>In VB.Net, the following declaration builds and executes with no
exceptions:

Dim XMLDoc As New XmlDocument
Dim Node As XmlNode

But in C#, the following (equivalent?!) returns the build error "XMLNode
does not exist in the current context.":

XmlDocument XMLDoc = new XmlDocument();
XmlNode Node = XMLNode;

Your translation is awry. You have the first line right: the translation
of

Dim variable_name As New type_for_variable

(a declaration and and assignment in one) is indeed

type_for_variable variable_name = new type_for_variable();

, and is in fact one of the rare cases where VB uses fewer characters than
C#. But where VB does a simple declaration:

Dim variable_name As type_for_variable

without actually assigning any value to variable_name, the C# maintains
its usual terseness-advantage:

type_for_variable variable_name;
--
Larry Lard
la*******@googlemail.com
The address is real, but unread - please reply to the group
For VB and C# questions - tell us which version

Aug 4 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by JJ | last post: by
3 posts views Thread by Mahesh Devjibhai Dhola | last post: by
5 posts views Thread by Paul | last post: by
1 post views Thread by andrej | last post: by
5 posts views Thread by Mahesh Devjibhai Dhola | last post: by
1 post views Thread by PaulF | last post: by
5 posts views Thread by =?Utf-8?B?VGhlIE1hbiBGcm9tIFNRTA==?= | last post: by
2 posts views Thread by =?iso-8859-1?Q?Norbert_P=FCrringer?= | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.