Over a million developers have joined DZone.

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.


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";


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.


Published at DZone with permission of Shafqat Ahmed. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}