Shared Methods

pasensyoso_manigbas

Well-known member
Joined
May 19, 2006
Messages
64
Programming Experience
Beginner
hi mods,

I only want to clear something out... As what I've read Shared Methods can only access members of the Class that are Shared... but what happen is when I access a Shared Methods with regular Methods... it does allow an access... and when a Regular Method access a Shared Method it also doesnt return an error... why is that so?:eek:
 
Shared methods don't know anything aboutn any specific instance of the class. All Shared methods are aware of as far as their class is concerned is the class itself. Other Shared members are members of the class, not a specific instance, so a Shared member can access them. Instance members are members of a soecific instance though. A Shared method doesn't know anything about any specific instance so it cannot access instance members.

On the other hand, instance methods know about the class itself and the current instance, so what reason would there be that an instance method couldn't access a Shared member? There isn't one. Instance methods can access Shared and instance members.
 
Now, shared members can't be evaluated using an instance of a class. But what happen to my code is, it evaluates the shared member using the instance of the class. This cant be happening right?.. but in my other class it goes with the rule, not evaluating the Shared methods using an instance of the class.
 
I really don't understand what you're saying. Shared members belong to the class and not to an instance. Shared members know nothing about any particular instance. That's the way it is and there are no exceptions. Having said that, VS will allow you to qualify the name of a Shared member with an instance variable of that type, but that still doesn't mean that the Shared member knows anything about that instance. The compiler simply ignores the instance and uses the type. In VS 2005 you will receive a compilation warning if you do qualify a Shared member with an instance variable and you'll be told that it will be ignored.
 
Back
Top