I asked a question like this in an interview for a entry level programmer:
var instance1 = new MyObject{Value = "hello"}
var instance2 = instance1;
instance1.Value = "bye";
Console.WriteLine(instance1.Value);
Console.WriteLine(instance2.Value);
The applicant responded with “hello”, “bye” as the output.
Some of my co-workers said that “pointers” are not that important anymore or that this question is not a real judge of ability.
Are they right?
EDIT: The point was made that MyObject could have been a struct. That is a Good point. However, I did not post the full question I gave the interviewee. The full question had a class that was clearly a class (not a struct). It can be found here.
Understanding the difference between reference semantics and value semantics is crucial. It is fundamental to the design of the language and the type system. Understanding that references can be implemented with pointers is not particularly relevant for entry-level C# programmers; understanding the difference between copying by reference and copying by value is highly relevant.
Well that depends on what ability you were attempting to test. If the ability to rapidly and accurately predict the behaviour of trivial C# programs is relevant to your job then I’d say that it is a good test of ability.
If the abilities to determine when there’s not enough information given to solve the problem, and to ask the right questions to elicit that information, are relevant, then yes, this is a judge of relevant abilities. (A good candidate would ask to see the implementations of type myObject and member Value rather than assuming that myObject is a class and Value is a mutable property of type string.)
I say that all those abilities are relevant, and that this is a reasonable first question for an entry-level position.