.NET VB WinForms reference to the class

R

Rick

Hi,

In C++, if there's a class named clsMyForm, which has a static
("shared" in VB.NET) member variable named "Total" , and an instance
(object) of the class named oMyForm, the static member of the class,
can be referenced thru the instance as follows:
oMyForm::clsMyForm.Total

In VB .NET, if I have a Windows Form class named clsMyForm, which has
a shared member variable named "Total" , and an instance of the class
named oMyForm, how do I reference the shared members of the class thru
the instance oMyForm?

Thanks in advance,

Rick
 
J

Jon Skeet [C# MVP]

Rick said:
In C++, if there's a class named clsMyForm, which has a static
("shared" in VB.NET) member variable named "Total" , and an instance
(object) of the class named oMyForm, the static member of the class,
can be referenced thru the instance as follows:
oMyForm::clsMyForm.Total

In VB .NET, if I have a Windows Form class named clsMyForm, which has
a shared member variable named "Total" , and an instance of the class
named oMyForm, how do I reference the shared members of the class thru
the instance oMyForm?

Regardless of whether you *can* do this in VB.NET (which I believe you
can, although these days it might produce a warning) it's a bad idea.

It leads the reader to think that it's an *instance* member. Just use
the type name, which makes it obvious that you're accessing a static
member.
 
R

Rick

I still would like to know how to do this in VB .NET, if anyone knows.

Thank you in adavance
 
J

Jon Skeet [C# MVP]

Rick said:
I still would like to know how to do this in VB .NET, if anyone knows.

I believe you just reference it as if it were an instance member.
 

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