What is C# and .NET?
When I started programming professionally in the late 90s one of the earlier projects was a portal for Vodaphone. For this we used ASP (Active Server Pages) and server-side objects written in Visual Basic. For Microsoft devs and alongside a SQL database this was the contemporary approach for web development. Many of the early adopters of interactive web sites/portals/intranets used this tech stack.
On 13 February 2002 Microsoft released its new approach to development named the .NET 1.0 framework. This included an updated version of Visual Basic (VB.NET) and a new programming language named C#. Instead of separate scripting and compiled objects this new framework would compile to objects. It was a unified approach to development.
Moving forward the framework split a few years ago into .NET and .NET core, but have now unified at .NET 5.0. The other big change is that it became open source, so developers and can submit their own changes/improvements for consideration.
What is the difference between .NET and C#?
.NET is a framework, it has many libraries and includes the runtime required to execute the code. C# is a programming language used to programme against the framework. There are others available including VB.NET and F#.
What is IL (intermediate language) and how does the JIT (Just In Time) compiler relate to this?
Earlier I said the .NET framework compiles code for execution. What happens is slightly more complicated. When a project is built an object is created and this is coded in IL, partially compiled. When the code is executed the JIT compiler compiles it into machine code. This is all handled by the CLR (Common Language Runtime).
First time you run a project it will take time to run. The results are cached so subsequent runs are quick.
Why not just compile into machine code immediately? The answer is compatibility and optimisation. The project could run on different operating systems in different environments. JIT compilation means the same IL code deployed to different environments will compile and run optimised for that environment. Clever.
How does .NET support different languages?
As discussed, the framework supports different languages, all of which compile to IL code. Different languages have their own syntax, types and styles – so how does this work?
This relies on two aspects of the framework called the CTS (Common Type System) and the CLS (Common Language Specification) which is itself a subset of the CTS.
Each language has its own data types (int, decimals, strings etc). For example, VB.NET has Integer type and C# as int type. The CTS resolves both these types to a common Int32 in the IL code.
If you are coding publicly available objects, you will need to ensure the exposed code is CLS compliant, you can specially mark code as CLS compliant in development.
The .NET framework and languages continue to change at a pace. C# is now at version 10. Much has changed but sound development principles persist, as always.
#.Net,
#C#