What is .NET Framework?
Framework is a set of libraries or we can say that it is a collection of libraries and dll’s. dll is known as “dynamic link libraries”.
We can find these frameworks in C drive – windows – Microsoft.Net –
Framework – V 4.0. There are different dll’s in the frame work for eg.
System.Design.dll, System.Device.dll, etc.
What is Visual Studio?
Visual Studio is an IDE i.e. Integrated Development Environment, which helps to integrate the framework with the language to compile the code.
Visual Studio uses C# language.
Following is one of finest start-up video to start with basics of C# step by step it will boost your practical understanding: –
Also have a kick start with step by step learn ASP.NET MVC 5 video as below: –
Steps for .Net & C#:
Step 1: To start learning .Net and C#, we must first install the software of Visual Studio (latest version). The link for downloading the software is given here:
Here is a screenshot for the download link:
Here we have to download the Visual Studio Community version.
Step 2: Download from the above link and install the software. This is how Visual Studio looks.
Step 3: Now for starting new project go to File – New – Project.
Step 4: After selecting new project, go to Visual C#. In middle we will see a number of templates from which we have to select Console Application. After doing that give the name of the project as (MyFirstConsoleApp). Click OK after that.
Step 5: After that we will see our project screen where we will write the code in Program.cs . Here in Program.cs we will see there are already templates present. Now we only have to write code.
Step 6: Now we will write the code which is,
System.Console.WriteLine("Hello World"); Console.ReadLine();
Step 7: After writing the code, we will build the code by going to the menu bar and selecting Build in which select Build Solution.
We do build solution to make sure that our code does not contain any error. As we can see in the screenshot above there are no errors found.
Step 8: After Building solution we run the program by pressing Ctrl F5 or by clicking the Start present in the tool bar. The output will be displayed in the black color screen or the Console or Command prompt as we say.
Now in the Console we see our output shown as “Hello World”.
As we have successfully completed and executed our first program, there are some questions which we will answer first.
1) How does the code compile in .Net?
As the code is written in C# language, it is formed into an IL(Intermediate Language) code and this IL code in run time is then compiled by JIT(Just In Time) compilation in to appropriate optimal machine language after which machine executes the code and provides output.
2) What is IL code?
IL code is known as Intermediate Language or in simple words it is also known as Half compile code.
3) Why do we need IL code?
Now sometimes we do not know that in which machine environment our code is going to run, so the IL code or the half compile code is created after which the JIT checks the machine environment i.e. hardware & software capabilities and according to that it compiles the IL code into optimal machine language.
4) What is JIT?
JIT is known as Just In Time compilation whose function is to compile the IL code into optimal machine language which the machine can read it and execute it.
Now in whatever language we write the code its IL code is going to be same whether the code is written in C# or VB.net or any other language.
After answering the basic terminologies we will see now that the IL code looks same for the code written in C# language and it also looks same when code is written in VB.net
There is a small demo which we will be doing step by step.
Step 1: Now as we have already done our first project of “Hello World”, in that just go into the Solution Explorer where we will see solution to ‘MyFirstConsoleApp’. Right click on that and then go to ADD – New Project. We have to add the new project in the existing project as we can see in the screenshot
Step 2: After doing that select Visual Basic – Console Application – write the project name as ConsoleApp1.
Step 3: After that we will see our project screen where we will write the code in Module.vb . Here in Module.vb we will see there are already templates present. Now we only have to write code.
Step 4: Now we will write the code which is,
Dim i AsInteger i = 10
Step 5: Now as we are showing the integer value i=10 in Module.vb by writing the above code, we also will change the code in our Program.cs to
int i = 10;
Now we will build the solution separately for both the projects and make sure there are no errors. Screenshot of building the solution separately for both projects is shown below.
Step 6: Now to view the IL code of both the projects Visual Studio has provided a tool called as “ildasm”. To use this tool we have to go to the Visual Studio Command Prompt. So we first have to go to the Start Menu in our computer,
Start Menu – All Programs – Visual Studio(2015) – Visual Studio Tools After clicking on Visual Studio Tools there pops up a folder in which we have to select Developer Command Prompt for VS2015.
Step 7: After selecting the visual studio command prompt, a command prompt box will appear where we have to write the tool name “ildasm”
Here after writing ildasm we see a separate dialog box of IL DASM.
Step 8: Now in the dialog box of ildasm go to File—Open, and here we have to open the file location of the project MyFirstConsoleApp which we made. After going to that location click on the folder of MyFirstConsoleApp and inside we will see two projects which we have made in two different languages.
Now go to the project which we named MyFirstConsoleApp – bin – Debug—MyFirstConsoleApp application file and open the file in ildasm dialog box.
Here are the screenshots of the following process.
Step 9: After we open this application file in ildasm dialog box we see,
We have to double click Main : void(string). After we double click the file we see a box in which the IL code will be present.
Here we see the int32 i which is declaration of integer.
Step 10: In the similar way by following the same exact steps given above we can open the project file of our other project and view its IL code.
We have to double click Main : void()
Here we have opened our other project named ConsoleApp1 and we can see its IL code.
Step 11: Now here we see that the IL codes of both the projects are same int32 i which is declaration of integer. The same parts are marked in red circles
So from this demo we come to know that whether the code is written in C# or VB.net or any other language their IL code are always the same and are compiled to a common type system.
After seeing how the IL code looks like we move to the further topic about CTS
CTSis also known as the Common Type System. As we know that there are many languages in .NET like C#, VB.net, VF.net, etc. Now sometimes we have to write the code in one language and run it or call it in other language.
To make sure that there is a smooth communication in between these languages they should have a common type system where after the compilation of the codes in their own language they form a common data type.
Therefore the main function of CTS is to make sure that the data types that are defined these different languages get compiled to a common data type. Hence they are known as Common Type System (CTS).