❓Stop Asking ‘Is C# Compiled or Interpreted?’ — Here’s Why

3 minutes

Is C# compiled or interpreted? This is a question that comes up very often in interviews involving C# and .NET. And in my opinion, it is the wrong question. An interviewer is asking a potential candidate this question in order to trick them into giving the wrong answer. Let me explain.

The Problem

Because, if we take the question as it is, what is expected from the candidate within the context of an interview? To answer something like “C# is compiled down to IL. The IL is interpreted to machine code from the CLR during runtime”. But this is an answer to a different question. So, the interviewer is expecting from the candidate to answer a question that wasn’t stated. The candidate has to guess that the interviewer wants to check their knowledge on how the .NET works. This is the intention of the question.

And this is why I think this question is misleading. Because it forces the candidate to guess what the interviewer wants to know while deviating from technical accuracy. What’s more interesting is that the technically correct answer to this question is that “C# is compiled period”. The job of the C# compiler ends at IL. The question was about C#, not about how .NET works. And that answer should be considered correct. But most interviewers will disregard it as wrong because the candidate didn’t mention that the IL is then interpreted to machine code (which itself is not 100% accurate but more on that later). But the question was not about IL.

So, in some cases it might even showcase the lack of knowledge of the interviewer, because they cannot tell the difference between C#, IL and machine code and how all these work together to execute a program.

How to do it better

So the technically correct answer to the original question is “C# is compiled”. But how can we fix that question in order to signal to the candidate that we want to check his knowledge on how .NET works. I think there are 2 ways we can fix the question. Either we slightly alter the original question into “Is C# compiled, interpreted, neither or both?”. This is better although definitely not technically sound. As we mentioned there is nothing interpreted about C#. The compiler emits IL instructions and stores them in the executable. Its job ends there. But at least, in my opinion, it offers the candidate a chance to understand what we want to know from them. It points them in the right direction.

The other alternative, and better option in my opinion, is to change the question completely. “How is a C# program executed?”. This is an open-ended question that gives the candidate the opportunity to showcase their knowledge. The candidate will tell a story the way they understand it, and the interviewer will get an idea of not only the candidate’s knowledge of .NET but also of their ability to explain technically complex topics.

Wrap-Up

What really happens behind the scenes, is something we will explore in another post. In the meantime, take a look at this article from the official Microsoft’s documentation.

Happy Coding!

Thanos