A Very Simple C# Interview Question That Most Developers Fail

We interview a lot of people and usually go through at least 3 interviews to select someone for the organization I work in. A recent trend of new developers is baffling me. The newcomer to development do not seem to know any of the basics. These newcomers might know some Linq, Ajax and famous frameworks but they fail at very simple OOP questions and fairly have very little or no idea about the CLR.

Anyway that is not the topic that I was going to write today, I have seen good candidates fail at a this question, which is basic knowledge. I don’t know why but this simple question baffles a lot of people. So I have decided to ask the readers this question.

Question:

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.

References
0

I am .NET developer following it from the first PDC. I love to work on CLR related stuff, Interop and WPF related areas. I design software and I love to design reusable and extensible frameworks. I am married to the love of my life and living in Dhaka, Bangladesh. Shafqat is a DZone MVB and is not an employee of DZone and has posted 9 posts at DZone. You can read more from them at their website.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Kaveh Shahbazian replied on Sat, 2008/10/04 - 2:38am

public class MyClass {

    public string Name { get; internal set;}

}

chen_dang86 replied on Fri, 2008/10/24 - 1:48am

it is exactly as Kaveh Shahbazian said.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.