As we know .Net framework supports multiple programming languages, but the C# (pronounced C-Sharp) is mostly used language in .Net technology. It is general purpose, modern, object-oriented programming language developed by Microsoft. C# is primarily derived from the C, C++, and Java programming languages, so it is easy to learn. You can create applications like windows applications, web application, web services, and much other application in C#.
Let’s read an introduction to C Sharp programming language.
Features of C#
C# is derived from C, C++ but it removes some complexities in these languages like macro, virtual base class, pointers. Most of the syntaxes are similar to these languages so it is easy for the peoples who are familiar with C, C++ or Java to learn C#.
It is a modern programming language and provides many modern programming features to developers like garbage collection, exception handling, and code security. All these features help to develop reliable and industry standard software.
- Object Oriented:
C# is object-oriented languages and it supports all OOPs concepts like inheritance, encapsulation, polymorphism and abstractions. As C# is an object oriented language you can divide code into classes and methods and reuse it many times. You also can create reusable class libraries.
- Type Safe:
C# is type-safe language and a programmer must declare data type of the variable before using it. You can not assign a value of one data type to another data type directly. The type-safe feature guarantees the security of data. All primitive data types in C# like integer, float, string etc. are derived from the Object. C# code is run under the environment of CLR (Common Language Runtime). CLR checks the data types in code and guarantees type safe code.
- Powerful and flexible:
C# can be used to develop many types of application like desktop applications, web applications, and mobile applications etc. under the environment of .Net.
- Garbage collection and automatic memory management:
In C# there is no need to allocate memory for your variable manually, C# automatically allocate memory for variables when they are created. Garbage collection is also one of the reasons for using C#. Garbage collector is a feature of CLR which frees the memory. There is no need to delete objects manually, garbage collector checks for unused references and cleaned up that memory. It is the background process.
C# language and .Net Framework:
The .Net is a software development framework from Microsoft for developing distributed systems. It provides the environment for developing and executing various types of application like windows application, web applications, web services etc. The .Net framework is multilingual platform it supports multiple programming languages like C#, Vb, J# and much more.
The .Net framework has following components
- Common Language Runtime:
The .Net framework provides runtime environments known as CLR (Common Language Runtime), which runs the code and provides a service that makes the development process easier. CLR provides core services such as memory management, thread management, remoting, and strict type safety enforcement.
- Common Type System:
There is a component CTS (Common Type System) through which .Net supports multiple languages to communicate with each other. CTS convert data types in different languages into a common data type.
- Framework Class Library:
The .Net Framework class library (FCL) or Base class library is the large collection of classes, interfaces, and value types. Using classes in FCL we can access Windows API. We can create any type of application with help of FCL. FCL is the object- oriented. It helps to optimize your development process.
- Common Language Specification:
The CLS (Common Language Specification) defines the rules that must be followed by every language which runs under the .Net framework. CLS is a subset of CTS.
Execution of code in .Net:
When a code is written in any .Net language like C# is compiled, it is not converted into machine specific language directly rather it is converted into MSIL (Microsoft Intermediate Language) by language compilers. MSIL is platform independent code.
When program executed MSIL is converted into machine specific code by the JIT (Just In Time) compilers in CLR. This is how .Net supports Architecture neutral application development.