object reference

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am starting to realize that there are differences in vb.net and c#:
in terms of syntax, object and keyword in small or big letter

In the routine below, I got this error message in c
An object reference is required for the nonstatic field, method, or property 'System.Web.UI.Page.MapPath(string)

But I would not get an error messaage if this same code is converted in vb. Please help. I am new in c#

private static void getnow(string dfilename)
XmlDocument docc = new XmlDocument()
docc.Load(MapPath( string.Concat("/virtualdirectory/", dfilename)))
....


Ray
 
C# is case-sensitive, VB.NET is not. So in C# "var" and "VAR" and "vAr" are
three different things, but in VB.NET they're the same.


--
____________________
Klaus H. Probst, MVP
http://www.vbbox.com/

Ray said:
I am starting to realize that there are differences in vb.net and c#:
in terms of syntax, object and keyword in small or big letters

In the routine below, I got this error message in c#
An object reference is required for the nonstatic field, method, or
property 'System.Web.UI.Page.MapPath(string)'
But I would not get an error messaage if this same code is converted in
vb. Please help. I am new in c#.
 
Just remove the static wor
It will work because it is no longer a constan

private void getnow(
instead of private static void hetnow()
 
Hi Ray,

As addition to Klaus,

VB is case insensitive but the VB.net IDE set it automaticly for you in the
propercase as expected (if it are no sentences between "") and therefore
you would probably not have so much problems with converting.

I hope this helps,

Cor
 
Ray said:
I am starting to realize that there are differences in vb.net and c#:
in terms of syntax, object and keyword in small or big letters

In the routine below, I got this error message in c#
An object reference is required for the nonstatic field, method,
or property 'System.Web.UI.Page.MapPath(string)'

But I would not get an error messaage if this same code is converted
in vb. Please help. I am new in c#.

private static void getnow(string dfilename) {
XmlDocument docc = new XmlDocument();
docc.Load(MapPath( string.Concat("/virtualdirectory/", dfilename)));
....
}

Yes you would - or rather, you'd get:

Cannot refer to an instance member of a class from within a shared
method or shared member initializer without an explicit instance of the
class.

"static" here is the equivalent of "shared"
 
Back
Top