The rise of the internet, demand for more flexible solutions to address real-world problems and constant evolution of programming languages gave birth to several core programming languages. C# is one such popular programming language that’s been around here since 2000 and enabled developers to build secure and robust applications that run on .NET or Mono framework.
Let’s explore C# along with .Net and Mono Framework one by one:
Microsoft, in the year 2000, released C# as the strongly typed language as the part of the .NET framework. C# is the type-safe object-oriented language that is highly expressive and easy to understand. C# provides the extensive library of useful classes that make your imagination is the only limit what you can achieve with this. C# implements all the object-oriented concepts like Encapsulation, polymorphism, and inheritance and it’s getting more reliable as new features are getting stuffed with every new update. The most recent version is C# 7.2, which was released in 2017 along with Visual Studio 2017. Visual Studio is Development and Debugging editor for .NET languages like C# and VB.
2. .NET Framework:
.NET Framework is the Software Development Framework developed by Microsoft to develop Softwares to run primarily on Windows platforms. Programs written for .NET Framework execute in a software environment(a runtime Virtual Machine) rather than in hardware environment. That runtime Virtual Machine is known as Common Language Runtime(CLR), one of the main component of .NET Framework, mainly responsible for memory management, security and exception handling purposes.
The two main component that makes the .NET framework are -
a.) Common Language Runtime(CLR)
b.) .NET Framework class library(FCL)
.NET Framework Class Library(FCL) is the huge collection of type-safe and language-independent classes to be used by developers while writing code. These classes are arranged according to their functionality called Namespaces. while as explained above, The Common Language Runtime(CLR) is the runtime component of the .NET framework that acts as a Virtual Machine to run the compiled code produced by the .NET compiler on the top of the Windows OS. Compilation of the code written using any .NET language is done by there respective compilers, like for C# there comes C# compiler, for VB there is VB compiler and so on.
Let’s see the complete steps of compilation and execution of the programs written using .NET Framework Languages like C# or VB:
- You write code using C#, VB or any other .NET language.
- During Compilation of that code using C# compiler or VB.net compiler, it does not directly convert to binary/native language; rather than it got converted into MSIL(Microsoft intermediate language) or IL(Intermediate language) along with some MetaData. MSIL(IL) + MetaData, together known as Bytecode. So we got Bytecode after compilation. This is your build. This is what known as Managed code.
- Your Build is ready now to deploy on devices. Please be aware, along with build there goes Common Language Runtime(CLR) attached to the build. During the execution of the code by the Just In Time(JIT) compiler of the Common Language Runtime(CLR) uses the Metadata to convert Intermediate Language(IL or MSIL) into native code, which is also known as Unmanaged code. So Bytecode converted into Native code(Unmanaged code) and VOILA your program is running on Windows device.
Important points to note:
- Managed code is .NET code (VB.NET, C# etc.) that you write and compile to .NET CIL.
- Unmanaged code is code that is not under .NET that compiles to direct machine code.
3. Mono Framework:
When Microsoft Released .NET framework it opened a vast possibility of creating powerful, flexible and robust software. But that was only intended for the Windows platform. What about the Others? — Then comes the Mono as an open source project in 2001 which brings the .NET Compatible framework classes to other platforms including its own c# compiler and CLR(Common Runtime Language). Today Mono supports almost all .NET features and still increasing its features.
The code execution for this framework is also same as the .NET framework :
- - You write code in C#.
- - C# code compiles using the inbuilt C# compiler and generates Bytecode or Intermediate language. That’s your build.
- - Build runs on target devices using the Bundled mono runtime environment(or Common Language Runtime). The mono runtime takes care of garbage collection, security, exception handling etc.
Mono’s Code Execution Engine: The mono runtime contains the code execution engine that converts the bytecode(IL) into native code. The code execution engine is exposed to 3 modes as follows:
a.) Just in Time(JIT) compilation: The runtime will turn bytecode into native code as the code runs.
b.) Ahead of Time(AOT) compilation: This mode of operation compiles most of the code before the code runs. Still, there are some exceptions like trampolines and others that still require JIT to function properly.
c.) Full Static Compilation: Only very few devices support this mode of the compilation like Apple’s IOS, PlayStation 3 and XBOX. This takes the AOT compilation one step ahead and generates all the Trampolines, wrappers and proxies and completely eliminates the need for JIT.
Well, the cross-platform feature of the Mono is one of the primary solutions for the software vendors targeting to support a vast range of popular platforms available in the market. For example — Unity 3D Game engine does so. You must also read How Unity 3D supports Cross-platform feature using Mono framework.
So, this was a short introduction to C#, Mono, and .NET framework and I hope it was clear to you. Your feedback, more explanations or critiques are most welcome :)
About Author: Niraj Vishwakarma, I am a Unity Game Developer in Indian based firm, having skills in the Mobile game, Augmented reality and VR app development and keen to work more on such technologies. I love sports too ;) My social profiles: Email | LinkedIn | Twitter