C# - Making fields/properties read only conditionally

Posted by Alistair77 on Stack Overflow See other posts from Stack Overflow or by Alistair77
Published on 2010-04-08T09:24:05Z Indexed on 2010/04/08 9:33 UTC
Read the original article Hit count: 182

Filed under:
|
|

I have three classes; Classes A and B both reference class C.

How can I make it so members of class C can be modified when referenced from class A but not modified when referenced from class B?

IE, the following should be possible;

classA myClassA = new classA(); myClassA.myClassC.IssueNumber = 3;

But this should not be possible;

classB myClassB = new classB(); myClassB.myClassC.IssueNumber = 3;

Making classB.classC read-only still allows properties of classC to be altered.

I'm sure this is basic stuff but can't find a simple answer.

Thanks, A

© Stack Overflow or respective owner

Related posts about c#

Related posts about readonly