My number one C# interview question

Vitaly Futoriansky
Sears Israel
Published in
5 min readDec 10, 2017

Interviewing is hard. You meet a new person for a few hours, and have to decide if this person can fit the position you are interviewing for, fit the culture and the dynamics of your company, the team, have a chance to meet the long-term expectations, and of course to understand if there is a technical match.

Let’s be honest, if you’re lucky it’s a sensible bet. This is why you have to use your time wisely.

I would like to share a flow that I use for the technical interview. Not all of it, only one of it’s aspects - in particular understanding a candidate’s depth of knowledge in C# programming language versus our expectations: his communication skills; unknowns handling skills; and his ability to craft a solution to a problem.

To do so, I ask the candidate to implement the LINQ ‘Where’ method:

I break this discussion into 3 parts:

  • Method usage
  • Method signature
  • Method implementation

During each of those parts there are different language capabilities to talk about.

There are no right or wrong answers - each answer can lead you in the right direction, candidates who improve or fix their answers on the fly can teach you how their process of thinking works, how they react to criticism and how they make decisions.

There are a lot of topics to discuss, so having a flow, helps to keep the discussion fluent and natural.

I always try to raise the bar with each subsequent question asked. Usually, the questions are dependent on the answers of the previous ones. Building an interview this way helps us to stop with each candidate at a different level, based on his/her knowledge.

As an interviewer I imagine the interviewee as a person who needs to get from point A to point B. I see myself as a compass that can suggest the direction if needed.

Ultimately, there are candidates who can walk the full distance by themselves, candidates who have used compass assistance, and candidates who got lost.

Eventually I measure candidate success by a set of parameters:

  • How far has the candidate have reached?
  • How big is the part of the path that was done using compass assistance?
  • How did he/she handle the challenges?
  • How did he/she react to criticism of their solution?

Usage

I start the discussion by asking the candidate to imagine we have a list of 100 random numbers, from which we need to filter out the first 3 even numbers existing in this list using LINQ.

The code I expect to see is something like this:

Discussions that can follow:

  1. Will the code work on Array or any other data structure? What interface should your data structure implement to make the ‘Where’ method work?
  2. Will the code run on the whole list or stop after it finds the first 3 numbers?
  3. What happens if there is no ‘Take(3)’ in the end, what does this method return? What if there is “ToList()” in the end.
  4. How is deferred execution achieved?

Additional themes :

  1. What are the differences, between: lambda expression, function and anonymous function, and can they all be passed as a parameter?

Common pitfall, and following discussion:

  1. Using ‘Select’ and not ‘Where’- what are the differences?

Signature

Once we have agreed on the usage, we move forward to the next part. Here I inform the candidate that Bill Gates has just called and said that Microsoft is canceling the support for the ‘Where’ method on its new C# framework release. Our code is full of ‘Where’ usages - so how can we save our code and fix all those compilation errors?

The answer is to implement the ‘Where’ method! We start from writing the signature, which eventually should look something like this:

Now we can discuss:

  1. What are extension methods? When to use them? Why not use an abstract class? Why are they static?
  2. What do we want to extend: IEnumerable/ICollection/IList /IQueryable? What are the differences between those interfaces?

3. How to solve the problem of unknown type (generics).

4. How to pass the condition? What are the differences between Func/Predicate/Action?

5. What are delegates?

Implementation

Most of the candidates I have met, will usually implement something like this:

Which is almost what we want, but when asked if this is a lazy/deferred execution, they will answer that it’s not. And they will be right, since this implementation always iterates over all the items.

The candidates who are aware of the ‘yield return’ functionality, will give you what you want:

Now you can discuss:

What is yield return and how does it work? When would you use deferred execution ? When not?

Summary:

  • Having a flow based around one main question, helps to keep the conversation natural and fluent, although a lot of ground can be covered.
  • Using the ‘Where’ you can cover: extensions methods, deferred execution, generics, delegates and more…
  • Growing level of complexity in questions saves time.
  • Each answer given can lead to an interesting conversation. Sometimes a candidate that starts with a bad answer and improves his answers as a result of the discussion can teach you more than the one who just knows the right answer.

How do you examine language skills at your company?

--

--

Vitaly Futoriansky
Sears Israel

So basically I love everything that involves buttons and people :) Software group lead and coder, electronic music producer and a synth lover!