Class Property (Accessor)

I have a question regarding accessibility of a field through a property.

I have a class "myClass" that contains a private field "myfield" with a public accessor "MyField" to be able to get and set the value of the field.

If I have a file "file_a.cs" that instatiates myClass I can access the field with a statement like myClass.Myfield. However, I have a file_b.cs that instatiates myClass also. How can I declare the accessor property in the shared class so that "MyField" is not available in file_b.cs but only available in file_a.cs?

Thanks

[618 byte] By [ROLIVIER] at [2007-12-25]
# 1

I'm afraid that there is no feature in the language that allows you to do this.

You can achieve something like this but only file_b.cs is in a different assembly and myClass and file_a.cs are in the same assembly. Then you can make the property "internal" so file_a.cs has access to it but not file_b.cs because it's in a different assembly.

MikeDanes at 2007-8-31 > top of Msdn Tech,Visual C#,Visual C# Language...
# 2
Just a side question, if the public part is called an acessor, and the private is field, does Property refer to the entire thing? If not, what? I thought private was a field and public was a property...
xRuntime at 2007-8-31 > top of Msdn Tech,Visual C#,Visual C# Language...
# 3

confused at your side note there...

public can be a property or a method, as so can private - the public/private is an accessor type. public can be accessed by anyone, private can only be accessed within the class itself.

you can make a private property in the class, then make a public property which other classes can access and you can control what they can do with the private property, such as get or set or even both together.

Does this make sense or is relevant to your question? :-)

ahmedilyas at 2007-8-31 > top of Msdn Tech,Visual C#,Visual C# Language...
# 4
Okay, I thought the original poster was referring to the public part as the "accessor"...
xRuntime at 2007-8-31 > top of Msdn Tech,Visual C#,Visual C# Language...