How do you define a property read only for the outside world and writable for the same assembly classes?
For example I have a class named User where everyone outside the assembly can read the string ‘Name’ property but cannot set it. However the classes inside the assembly is able to set the property. I am further detailing the exlanation.
User myUser = SomeClass.GetUser();
// OK for all classes since all can read it string name = myUser.Name;
// This line does not compile if this code is // written in a class that is not in the same // assembly as the type User. But it compiles // if the code is written in the same assembly // that contains the type user. myUser.Name = "C# Developer";
Answer:
Now all I want is the c# code declaration for the property name that matches my requirement of being read only for the outside world. Write it in the comments section. I will answer the question 24 hours from now.
simple C# interview question that most developer fails
How do you define a property read only for the outside world and writable for the same assembly classes?
For example I have a class named User where everyone outside the assembly can read the string ‘Name’ property but cannot set it. However the classes inside the assembly is able to set the property. I am further detailing the exlanation.
User myUser = SomeClass.GetUser();
// OK for all classes since all can read it
string name = myUser.Name;
// This line does not compile if this code is
// written in a class that is not in the same
// assembly as the type User. But it compiles
// if the code is written in the same assembly
// that contains the type user.
myUser.Name = "C# Developer";
Answer:
Now all I want is the c# code declaration for the property name that matches my requirement of being read only for the outside world. Write it in the comments section. I will answer the question 24 hours from now.