retrieving private property from shared public function

J

Jon Paal

In a 2.0 vb code class, I have a private property and a shared public function

The property value has already been passed into the class, now I am trying to use a public finction which also needs the property
value.

How can I use the private property from within the shared public function, without having to pass the property value back into the
class again?

attempting to use the value now returns this error message:
 
P

Peter Rilling

1) Make the property public. (Although it might have been private for a
reason).
2) Make the property internal (or in the case of VB, probably a "friend").
3) Use reflection to get access to the private property. (The program will
slow because reflection is slower than direct access).

You have to ask yourself, why are you trying to access a private member.
Usually things that are private as such for a reason, otherwise they would
have been exposed to the world.
 
K

Karl Seguin [MVP]

A shared member can't access an instance member with having an instance.

so if you have

public class Test
private name as string

public shared sub DoSomething()
'can't access name from here since name is an instance member
end sub
end class

It doesn't make sense why you'd want to, so perhaps if you explain what ur
tryin gto achieve.

karl
 

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