XMLNode

E

Earl

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;
 
J

Jon Skeet [C# MVP]

Earl said:
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
 
L

Larry Lard

Earl said:
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;
 
E

Earl

Thanks to both you and Jon.

Larry Lard said:
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
(e-mail address removed)
The address is real, but unread - please reply to the group
For VB and C# questions - tell us which version
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top