Specifiy that i'm referring to a class, not a member

W

wingphil

Hi all,

I've got a class in my project called Location - it has some shared
members that I can't reference from within a form because forms have a
property called location. Short fo renaming the class or putting
Projectname.Location.Member which is a bit wordy for my liking, how can
I tell the compiler I'm talking about the Location class, not the
Location member? I'm using VS 2003.

Thanks very much for any help you can offer,

Phil
 
M

Mythran

Hi all,

I've got a class in my project called Location - it has some shared
members that I can't reference from within a form because forms have a
property called location. Short fo renaming the class or putting
Projectname.Location.Member which is a bit wordy for my liking, how can
I tell the compiler I'm talking about the Location class, not the
Location member? I'm using VS 2003.

Thanks very much for any help you can offer,

Phil

You could use "Imports MyLoc = MyNamespace.Location". Then you could use
MyLoc.MemberHere :)

HTH,
Mythran
 
Z

zacks

That's great, didn't know you could do that :)

Thanks Mythran!

Phil

I use that same trick to provide shortcut references to VB functions as
in:

Imports VB = MicrosoftVisualBasic

If VB.Left(blah) ...
 
M

Mythran

I use that same trick to provide shortcut references to VB functions as
in:

Imports VB = MicrosoftVisualBasic

If VB.Left(blah) ...

Usually, we don't do that in our office. But once in a great while, there
comes a time where two namespaces collide. For example:

SomeCompany.Security.Principal namespace, System.Security.Principal
namespace and OurCompany.Security.Principal namespace. We don't want to
type out the full namespace, so we just use the specified imports shortcut.
Another thing that we usually don't use, but have done...albeit rarely, is
import a class directly so that we don't have to type out the class name....

Example:
We have a class named Common with all shared members. We just want to call
the members/methods directly without specifying Common everywhere... (this
only works in VB.Net and not C# afaik)...
Imports OurNamespace.OurApplication.Common

Here we directly import the namespace + classname and now instead of
Common.MethodName() we can just use MethodName() ...

Cheers!

Mythran
 

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