C# is a programming language developed and maintained by Microsoft. It is one of the most used programming languages of modern software development. It was pretty much influenced by Java when it was originally released. It is having all the rich features and characteristics of a true object-oriented programming language.
History and Evolution of C#
C# was created as a part of Microsoft.Net suite of tools which was more of a big plan of Microsoft to create a one-stop development framework for all. With the increasing popularity of Java, Microsoft wanted to revamp their Visual Studio 6.0 suite. It turned out that Microsoft had decided to create an entirely new framework from scratch. I must say - the birth of.Net framework along with C# was as a revolution for developers. It was first released in 2000.
C# was created by Anders Hejlsberg ( ) and he still is the chief architect of C# at Microsoft. All releases and maintenance of C# are being carried out under his supervision only.
The first version of C# was shipped as C# 1.0. Much sooner C# 1.1 was released which was more of minor improvements. However, C# 2.0 had breakthrough changes like generics, partial types and anonymous methods. This actually made more developers on-board to C# and.Net framework. Please refer the following table to know C# version changes in brief:
|C# version||.Net framework version||Visual Studio version||Feature Additions|
|1.0||1.0/1.1||Visual Studio 2002||Initial release of C#|
|2.0||2.0||Visual Studio 2005||Generics, Partial types, Anonymous methods, Nullable types, Iterators, Covariance and contravariance|
|3.0||3.0/3.5||Visual Studio 2008||Auto-implemented properties, Anonymous types, Query expressions, Lambda expression, Expression trees, Extension methods|
|4.0||4.0||Visual Studio 2010||Dynamic binding, Named/optional arguments, Generic covariant and contravariant, Embedded interop types|
|5.0||4.5||Visual Studio 2012/2013||Asynchronous members, Caller info attributes|
|6.0||4.6||Visual Studio 2013/2015||Static imports, Exception filters, Property initializers, Expression bodied members, Null propagator, String interpolation, nameof operator, Dictionary initializer|
|7.0||4.7 and Core 1.0/2.0||Visual Studio 2017||Inline out variables, Discards, Pattern Matching, Local functions|
C# 8.0 is the newest version (that is about to release) at the time of writing this chapter. It introduces some cool features like patterns in a switch statement, properties, tuples and positional. It also includes static local functions, nullable reference types, asynchronous streams, Indices and ranges (more or less similar to Python).
The .Net Framework
.Net framework is a managed execution environment to execute and manage applications that are built using .Net technologies like C#, F#, ASP.Net etc. The framework is responsible for providing the following functionalities:
- Memory management: Without having to explicitly allocate and deallocate memory while developing Apps, the .Net runtime takes care of memory management.
- A common type system: The .Net framework supports different language which has their own data types. To make these type compatible for .Net framework, all these types get converted into a common type by the programming languages' respective compilers. This also gives .Net cross-language compatibility.
- .Net framework class library: A huge set of frequently used functionality is provided by .Net framework covering most of the use cases. This makes developers to use classes and methods instantly without having to explicitly code it.
- Side-by-side execution: This means that different versions of .Net framework can exist in the same machine and multiple versions of Apps can execute on a single machine without any conflict.
- Multi-targeting: Same code can be targeted to multiple version of .Net. This is provided by .Net standard.
.Net Architectural Components
At the core .Net framework is an implementation of .Net specification. There are various implementations of .Net specification and that includes .Net framework, .Net Core and Mono.
It is an implementation of an API specification that is common to all implementations. It provides a unified set of contracts so that the application can be targeted to any implementation. If we target our application to .Net standard, we can be sure that our app can run on any implementation(s) provided by .Net framework.
There are currently 4 implementations of .Net specification supported by Microsoft.
- .Net Core : It is an implementation of .Net specification that targets multiple platforms like Windows, MacOS, and Linux. The app developed in .Net Core can be executed on one or more of these platforms.
- .Net Framework : The .Net framework is the same that exists since inception. This will continue to provide a development platform to develop windows based applications. It contains many tools and libraries that are subject to windows platforms like Windows Forms, WPF, Microsoft Office components etc.
- Mono : It is a .Net implementation that is used to build very programs. It basically supports the Microsoft native mobile development platform Xamarin.
- UWP (Universal Windows Platform) : This implementation is used to develop applications built for IoT (Internet of Things) and across various devices.
CLR (Common Language Runtime)
The .Net framework provides a runtime use to execute and maintain the lifecycle of an application built using .Net framework in a managed execution environment. The applications developed in different.Net supported language gets compiled into MSIL (Microsoft Intermediate Language) by their respective compilers and then some additional metadata gets associated with this MSIL to form the Assembly (Assembly will be covered in a later chapter in detail). This metadata tells the CLR about program's types, members and references. In this way, the CLR uses this information to execute the overall application irrespective of in whatever language it was built.
CTS (Common Type System)
A CTS in .Net framework provides a model for different types that are implemented by various languages provided by the framework. Each type of a .Net programming language has its equivalent type in CTS. Thus when the code is compiled into MSIL, the language types are converted into CTS types and thus it makes CLR understand the MSIL without worrying about the language in which it was compiled.
CLS (Common Language Specification)
CLS provides a way to make .Net build applications fully interoperable. This means that the code written in one language can be used/consumed in another language.