Part of the duties of a senior team member is to interview candidates for open positions. This task comes up for various reasons: attrition, growth, and new projects. Doing interviews are part of the job.

When interviewing developers I like to give them the opportunity to self rank (from 1 .. 10) on their understanding of a language or technology. I will ask something like:

If 1 is a complete beginner and 10 means you're an expert in Y, where would you rank your understanding of Y between 1 and 10?

I like this question because it allows the candidate to consider where they stand, and more importantly, what they want to share.

  • A rank of 10 would seem arrogant. Even if you were an expert I would guess that you should not say 10.
  • 8 & 9 is the sweet spot. The goal is to be honest with yourself first. There are always things you do not understand. How willing are you to risk the follow up question?
  • 7 is where most candidates land. It says I know some things but I am not the best.
  • I am sure nobody has ever answered 6.
  • A rank below 5 would only be acceptable for junior positions.
  • I just wouldn't accept anything below 4.

If you are a C# developer, and you say 8+ you will get the followup question: "How many uses of the keyword `new` exist in the C# language?"

In the C# programming language the `new` keyword can be used as:

  • operator
  • constraint
  • modifier

Most developers use and will provide examples of using the operator to instantiate objects and arrays.

The new operator used to invoke constructors, arrays, and instantiating anonymous types. This is the most common usage and documented here.

// object
var str = new StringBuilder();
str.Append("new operator");

// array
var newTypes = new int[3];
newTypes[0] = 1;
newTypes[1] = 2;
newTypes[2] = 3;

// anonymous
var a = new { Text = "anonymous object" };
Console.WriteLine($"{a.Text}");

Someone who has programmed C# professionally will have used generics. If they wrote generic classes they may have encountered the constraint usage. This is good indicator they are writing libraries or shared code for their projects.

The constraint where T : new() ensures the type has a default (parameter-less) constructor and is documented here.

// constraint
public class Factory<T> where T : new()
{
  public T Create()
  {
    var o = new T();
    // initialize 'o' with common params
    return o;
  }
}

The final usage for the keyword new is as a modifier. This modifier is used to when a method in a class conflicts or hides the base class method of the same name.

I have only used the modifier when integrating into an existing library or shared code, and I absolutely refuse, or cannot, change the name of the class member. If you are okay with changing the derived member name, even just adding a character, then this modifier is generally not required.

The modifier usage is documented here.

// modifier
public class BaseClass
{
    public string Name { get; } = "Base";
}

public class DerivedClass : BaseClass
{
    public new string Name { get; } = "Derived";
    // just change the name b/c they really are 2 different members
    public string Name2 { get; } = "Derived";
}

Most developers I have interviewed have answered there are two (2) uses for the keyword new. This is the answer you are looking for.

The goal is to get the person talking about development. You will encounter developers using all three (3) variations but not having that named ready during an interview. That is why talking about development during the interview is your greatest weapon in the interviewing arsenal.

Keep them talking. Keep them engaged in the interview. This question is just a simple way to allow for some reflection during that process.

This post was originally published on 9/22/2021 and has been edited and updated.