Introduction to What is .NET?
When we say .Net, basically it’s a technology from Microsoft. Few years back, it has only VC++ and VB Script to compete with java. Nowadays the world is more dependent upon the internet/web. It’s a framework developed by Microsoft which includes a huge amount of class library which provides language interoperability across various programming languages. Any program we write in .Net framework gets executed in a software environment which is known as Common Language Runtime (CLR). It provides functionality such as security, exception handling, and memory management. Microsoft provides an integrated development environment for the .Net software called as a visual studio.
Framework Architecture of dot NET
We can see the 1st layer in the diagram consist of all the different languages. Its architecture is modular, tiered or you can say hierarchical. It has a layer of abstraction. Most abstracted level top tier consists of .Net languages.
1. Common Language Specification
Common Language Specification (CLS) is a group of some basic language features which .Net Languages needed for the development of applications and services, that are compatible with the .Net Framework. Common Language Specification (CLS) ensures interoperability among applications completely, regardless of the languages which are used to create the application. For organizations looking to leverage these powerful features and create robust, scalable solutions, partnering with a provider of custom .NET development services can be invaluable. They offer expertise in CLS and other advanced .NET capabilities to build tailored applications that meet specific business needs.
2. Common Type System
CTS is a part of .Net CLR which is responsible for type safety within the code. CTS basically deals with data types. we have various languages and each one of them has its own different data types which cannot be understandable by other languages. However, .Net framework language can understand all the different data types. Its main purpose is to make it language independent.
CTS is a catalog of .Net types. System.Int32, System. Decimal, System. Boolean, etc. Developers are not needed to use these types directly. These types are in each managed language and these types are underlying objects of the specific data types which are provided
3. Framework Class Library
FCL provides access to system services. Some of the available services are remoting, XML, database access and file input/output. It is a set of classes, interfaces, namespaces, and value types which are used for .Net applications. It also supports exception handling. It has the ability to create windows based GUI applications, web-client, and server applications.
4. Common Language Runtime
The common language runtime is close to the native environment and in the bottom tier also the least abstracted. CLR works closely with the operating environment to manage all the .Net applications. JIT (Just-In-Time) is a compiler that is used to convert the managed code into machine instructions which will be executed later by the CPU of the computer. Basically, it provides an environment to run the .Net application on a given target machine.
5. Common Language Infrastructure
It provides a virtual execution environment. It uses a compiler to process the language statement which is also known as source code into a preliminary form of executable code. It is designed in such a way that makes it easier to develop programs that can be used as web services. CLI programs can be written in various programming languages like C++, C#, ASP, etc. These all languages are compiled into CLI. CLR then compiles into machine code for further processing.
Why we Use .Net?
- It has centralized data storage, which results in increased efficiency.
- Synchronization of information with the users and devices.
- Easy to access the information.
- It has the ability to integrate media, fax, telephones, and various communication.
- It allows the developers to use the modules which were already created by them that are reusable modules.
- Reduces the number of errors and increases productivity due to reusable modules.
- Popularity for interoperability.
- It understands many languages. So, this framework is language-independent.
Building Console Application
Example to create a console application to display the message “Hello EDUCUBA World” by using Visual Studio. Before starting with it you just need to have any version of visual studio installed on your machine. Let’s proceed to create an application with the following steps:
Step1: First you need to create a project in visual studio. For that you need to launch a visual studio, Here I am using visual studio 2019. Once the visual studio is launched you can go to File->New->Project as shown below
Step 2: The next step you need to do is choose the project type as a console application. Where you can change Project Name and Location or keep the default name.
- We can see multiple options to create a different project in Visual studio. We need to select the Windows Desktop option form the left-hand side.
- Once we click the Windows Desktop option, we will see the option to go for Console Application. Just select that option.
- Now we need to give the name to our application, here we have given MyConsoleApp name to the project. We can provide our project location to store our program.
- Lastly, click the “OK’ button to ask the visual studio to create our project.
Step 3: When we click ‘Ok’ in the last step. Visual studio internally creates our project “MyConsoleApp” at a given location. This project will have all the required artifacts to run the console application.
If you noticed the highlighted rectangle on the image below. It shows Solution explorer which has our Project name and necessary files for our console application.
If we open Program.cs, we will see some default code is already placed in the file. For sake of purpose, I have added lines no. 16 and 17 which will be used to write the “Hello to EDUCUBA world”.
Code Explanation:
- The “using” statement is basically used to import dot Net Modules. Which are used to run .NET applications properly.
- Every .NET application runs around the class. Hence whichever code we want to get executed we need to define that into the class. As well every class belongs to a namespace. Where namespace is called a logical group of the classes.
- The main function automatically gets called when the console application gets executed. Hence, we need to enter the code here which we want to get our program is intended to execute.
- The Console class exists in the System .NET System namespace. Hence we use the building WriteLine method to write the string “Hello to EDUCUBA world”
- ReadKay() is used to ready any key from the console. Until we enter any key program will wait for the key and will not exit. Without this line, the program will get exit immediately after it runs.
Step 4: To run the program, click the Start button as shown below.
If we don’t have any errors in the program it will get executed successfully, and it will show below output on the console.
We can see clearly the “Hello to EDUCUBA world” message on the console, this is due to Console. Writeline statement which caused to send a string to console.
Conclusion
We have learned what is .NET? why we use .Net and its uses for example. As it supports many languages it’s easy for developers to choose any language to develop their application. However, we can say that .NET is considerably more flexible. Also writing a program is a task of fewer efforts as .NET provides default artifacts.
Recommended Articles
This has been a guide to What is .NET? Here we discuss the introduction, Framework Architecture of .NET. Why we Use .Net? and building a console application. You may also have a look at the following articles to learn more –