Birdman
Birdman

Reputation: 5414

Class members only accessible from methods of the same class - How?

I've stumbled upon the following two "weird" looking properties:

Process.GetCurrentProcess().MainModule;

Assembly.GetExecutingAssembly().Location;

These properties are a part of the class Process and Assembly, but the properties are only accessible from methods inside those classes.

Neither Private or Protected restricts properties to only being useable from methods inside the same class.

What do you call the protection level of these properties or how does this work at all?

Upvotes: 0

Views: 107

Answers (2)

Reza ArabQaeni
Reza ArabQaeni

Reputation: 4907

GetExecutingAssembly is a static method that return a process Type, With this type you can access the public properties such as MainModule like this:

new Process().MainModule

So you confused a class and a object of that class.

Upvotes: 2

Hogan
Hogan

Reputation: 70513

That is what private does

http://msdn.microsoft.com/en-us/library/ms173121(v=vs.80).aspx

"Finally, a class or struct member can be declared as private with the private keyword, indicating that only the class or struct declaring the member is allowed access to that member."

Upvotes: 3

Related Questions