Meet Microsoft .NET

Before writing applications in C#, understanding the .NET is very important. Usually, beginners who are moving to C# don't care about understanding .NET? In this article, you will learn what .NET and its components are?

Today there are more than 400 Million computer users in the world and I think almost all of them use the internet daily for shopping, chatting, business and many other things. But still there are a lot of things that they can't do it by using the internet like if there are available seats of Air France plane that will go to Paris next week, And maybe you want to know the prices of other air lines and compare it to Air France and choosing the less expensive one, Maybe you want to know the nearest car renting company and if there are more than one company you will choose a car and compare the renting charge between the companies, And many many things that will make our life much easier like sending a message to my car that will receive my command via .NET to do something maybe open the door after 5 minutes.

Before Microsoft. NET all these services were a dream and simply don't exist because there are no computer platforms that capable to deal with these services, Also every vendor use some technique for describing their information, And we must not forget that developing the code necessary to integrate such services is very complex, Microsoft realize that the future for internet especially these kind of services and they must improve the capabilities of the these services so Microsoft spent 3 years creating .NET and released it in July 2000.

Actually Microsoft considered creating these web services as the future of selling Computer Applications. For example, your company specialized in creating services for car renting companies so car renting companies will be interested in your products and buying it. Also there will be a free services offered by a number of companies. You can think of these web services as a new way of executing business logic and here are some examples of these services:

  • Service for specifying the nearest Car Renting Companies in my area based on my zip code. 
  • Service for comparing books prices.
  • Service for providing times, for example a service that will provide the local US time for other countries.
  • Service for air lines tickets comparing based on the information entered by the user.
  • Service that capable to search for Internet users every specific hour.

These was a very simple list of web services that companies can implement and believe me the list can be Millions of services. Microsoft and a number of companies begin developing such kind of services and some of them will be for free other will not. With these great services there must be produced applications that will use these services to do its job. For example, we have a service that will retrieve the renting car companies based on the zip code area so we must develop an application that will use this service and return the result to the user of the application so now with a thousands of these services and applications to use these services we will have a rich powerful applications for the users.

So to create these powerful applications there must be a programming platform which capable to use these services through a powerful international network like the internet and make the whole world like an integrated unit and this all Microsoft. NET about.

Important Note: The concept of Microsoft. NET maybe not clear for now but when you know more about C# and when you work with Web services you will get the big picture. So don't worry because we are just in beginning.

In Microsoft. NET world these services called web services and these web services all connected to the internet (so applications can use these services). There is a part of Microsoft. NET called .NET Framework which provides the developers an easy way to access web services so .NET Framework is the development platform that we will use to develop .NET applications. In a few words we can say that Microsoft. NET platform is the group of technologies and products that Microsoft spent the last few years and about 80% of its budget in .NET researches and development. I think you will understand it better after we talk about the components of that huge platform.

Microsoft. NET Platform components

Most of you will think that Microsoft. NET Platform just C# and Visual Studio.NET but C# and Visual Studio.NET just part of the big game. And as I said before Microsoft. NET it's just a name for a lot of technologies. Here in the book we will need to know that C#, Visual Basic. NET, Visual Studio.NET (VS. NET) and .NET Framework (which we will discuss next section) are parts of Microsoft. NET Platform and that's what you need to know.

But to get the whole picture in your mind you must know that there is a group of servers like (Microsoft SQL Server 2000, Microsoft Application Center 2000, Microsoft Mobile Information Server 2000 and many others) Microsoft call these servers '.NET Enterprise Servers' and this is another part of Microsoft. NET Platform. Also as a part of Microsoft. NET world and Platform there are a number of new non-PC devices like Pagers, Mobile phones and many others will be part of .NET technology, how? Simply these devices will be able to receive .NET applications. Also there are a number of services called .NET services and it's a part of Microsoft. NET Platform.

Now that you have a good overview about .NET Platform we must understand 2 major components of this Platform.

1. .NET Framework
MSDN and many books describe the .NET Framework as "The .NET Framework is a new computing platform that simplifies application development in the highly distributed environment of the Internet". Or ".NET Framework is completely new application development platform". Actually if this is your first programming book then you may not understand .NET Framework like that.

When you develop applications using C# or any other language that can work on .NET (support .NET) there must be a way for the Operating System to understand the applications and execute it and that's the role of the .NET Framework. Let me explain it this way: We have some programming functionality in C# (I try to use simple expressions here) that enable us to generate a random numbers in our programs so when we write this function's code how C# will talk to the operating system (Here is Windows Platform) to generate that random number?
Pretty easy using .NET Framework, so .NET Framework knows how to talk to the Operating system to generate the random number. Think of .NET Framework as the programming framework for C# (actually as we will know later for all .NET Languages). So when you program using C# the .NET Framework will understand the code you wrote and talk with the Operating System to execute your program.

Now when we say "The .NET Framework is a new computing platform that simplifies application development in the highly distributed environment of the Internet" so we understand that .NET Framework a new platform that will help us developing applications fast and easy while abstracting a lot of complex operating system details. Let's get back to our example of generating a random number. If you want to generate it using non-.NET languages so you must develop a complex mathematical calculation and you will need to get the time of the Computer for this calculation too so you will deal with operating system. But with .NET Framework we don't have to know these operating systems details and simply we will use the functionality provided by the framework to get the random number generated. Now that you have a good simple understanding of .NET Framework you must know 2 central components.

.NET Framework Central Components

  • .NET Framework Class Library (FCL)
    For now think of this as the programming functionalities and capabilities that we will use to develop your applications, in our Random Number Generating we use a function to perform the Number Generating and this function part of this Class Library not only that but you can develop windows applications, web applications, network applications and more using this library. 

    Important Note: We didn't study the concept of classes yet so don't worry. Just understand that FCL contains the programming functions that you will use to develop all kind of applications.
  • .NET Common Language Runtime (CLR)
    This is a major part of the .NET Framework but before we know what is its function we must understand what does Runtime means?
    Runtime is the time when you execute your program. I mean the time when your program is running in memory. As its name says it's the language responsible of running and executing .NET applications and managing memory. Before .NET memory management was the programmer's responsibility and believe me it was one of the worst nightmare for programmers but with .NET the CLR will manage memory and that's will result to a better applications performance.

2. Visual Studio.NET (VS. NET)
Visual Studio.NET is major and important components of Microsoft. NET and Microsoft spent many years developing visual Studio.NET.

When you write C# applications you can use command-line C# compiler but it will be very complicated and tedious for writing even the simplest C# application so Microsoft Developed Visual Studio.NET and using this powerful tool you can save a lot of time writing applications. We have a drag-and-drop style where you can drag a button and drop it on a form in the right position without writing any code but if you are using command-line C# compiler you will have to write many lines to just put the button on the form. Visual Studio.NET is the Microsoft development Environment for .NET applications so when you develop .NET applications you will prefer to use Visual Studio.NET.

MeetNetImg1.jpg

Figure 1.1 displaying VS. NET development environment when you open it.

Compiling .NET Code


As we said before that high-level languages (like C, C++ and C#) use a compiler to compile (convert) its code to machine code language that the operating system will understand and use this code to execute the program. But this not exactly what happen with .NET languages there are 2 steps for compiling the .NET Code.

.NET Framework compile all .NET languages (like VB.NET, Visual C++.NET and Visual C#.NET) into Microsoft Intermediate Language (MSIL) using MSIL compiler. Do you remember when we said that high-level languages use the compiler to compile the code into the Operating System machine code and only this operating system will understand that code but when we compiling .NET code into MSIL code not specific to any operating system so we still need 1 more step. We need to compile MSIL code into the operating system specific Machine Code and it's the job of Just-In-Time (JIT) compiler. .NET Framework use the JIT compiler to compile the Microsoft Intermediate Language code into Machine Code specific to the operating system and now .NET applications can run on this operating system. So we have 2 steps first we compile our C# code to MSIL code (which is not specific to any Operating System and it's specific to .NET Framework and only the .NET Framework can understand MSIL Code) after that we will use the JIT Compiler to Compile MSIL Code into the Machine Code.

Why there are 2 steps while we can have 1 step?

There are a number of reasons for compiling .NET applications in 2 steps and for now we will know some of them.

All .NET languages' Code compile first to MSIL code (this called 'Language Interoperability') which is specific to .NET, I mean that .NET Framework understands MSIL code and not the operating system. So for example, Imagine that we are working in the same company and you are Visual C#.NET programmer, other developers work with Visual C++.NET and I'm working with Visual Basic.NET and because all these different languages' code will compile to MSIL (as a first step) so we can work together in the same project and everyone of us will still work with his favorite programming language and there is no need to learn the other languages and after we finish the project Visual Studio.NET will compile the code to MSIL Code from the 3 languages after that JIT compiler will be used to compile the code to the Machine Code.

If MSIL does not exist then we can't work together because every programming language's compiler will not understand the other programming language code. But MSIL compiler understands all .NET languages code.

They call JIT compiler Just-In-Time compiler because it compiles the MSIL Code only when it need to. MSIL Code compiles and saves to a file in the disk and when we need to run the application JIT will do its job so it's just in time. JIT compiler is specific to the Operating System and the platform so to compile C# code on Windows NT\2000 Platform you need a specific JIT compiler and if you want to compile the code on another platform (like UNIX) you will need another JIT compiler specially created for that Platform.

Managed Code vs. Unmanaged Code

When we write .NET code that uses the services, functions and capabilities of the .NET Framework Class Library (FCL) then we call that code Managed code because it's managed by the Common Language Runtime (CLR). As you know that the CLR manage the execution of .NET programs and managing the code is one way of managing .NET applications. When we write Managed Code we don't care about Memory management, Handling operating system low-level functions because CLR abstract these details from us and manage it. So writing managed code will improve applications performance.

You can write "Unmanaged Code" too. It's the code that not managed by the CLR and it's your responsibility to manage the memory and many other things, CLR can't control this kind of code but in the same time this code is a powerful feature because you will gain access to the low-level operating system functions and maybe will be useful in some circumstances.
But the most of us will use the managed code and benefit from CLR management and capabilities

C# Overview

C# is created by Microsoft as the primary language for the .NET Framework, Microsoft designed C# in a way to make it easy for C, C++ and Java programmers to migrate to .NET. C# has roots in C, C++ and Java so this migration is easy for these languages' programmers. C# syntax not complicated like C++ so learning C# is much easier that C++ and almost all of the operations that you can do it with C++ you can do it with C# except for the operations that access low-level operating system functions but you still can do these operations using unmanaged code. C# is the best .NET language because it's the only language that designed specially for .NET Framework and it will be the first language that will support .NET Framework versions on the other platforms.

.NET Framework Applications

With .NET Framework we can create any kind of applications that we want but like the console applications which are simple command-line interfaces without any windows, Windows Applications which are applications with complex interface which contains buttons, menus, text boxes, option boxes and many other visual components, There are also web applications and web services which is internet-based applications and it's the core of Microsoft. NET technologies as we stated before. You will understand the different kinds of .NET applications as you go further in the .NET world. Here in the book we will discuss the first 2 kings (Console applications, Windows applications) only.

.NET Framework and .NET Languages

When we say .NET languages we mean any language that work on the .NET Framework. In other words, we can call any language that uses the .NET Framework Class Library (FCL) and managed by the Common Language Runtime (CLR) a .NET- compliant language (languages which support .NET Platform). From These languages: Microsoft Visual Basic. NET (VB.NET), Microsoft Visual C++.NET and there are also COBOL, Eiffel, Jscript, RPG and many others. But as we stated before that C# designed especially for .NET Framework and there are some functionalities in C# you can't do it in other languages. However, Microsoft developed Visual Basic. NET as an upgrade for Visual Basic programmers who like to work with .NET Platform.

All .NET-compliant languages will use FCL and CLR for creating applications. For example, VB.NET programmers will use the same function that C# programmers will use to write a line to the console (console means the command-line screen) but of course there are difference to get this code done. Let's look at the following .NET applications.

This is the C# application that will write a line to the console

using System;
namespace testApp
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
Console.WriteLine("I like C# Programming");
}
}
}

This is the VB.NET application that will write the same line to the console.

Module Module1
Sub Main()
Console.WriteLine("I like C# Programming")
End Sub
End Module

When compiling and running any of these applications you will get the same results.

I think this article was a very simple introduction to .NET and if you want know more there are many books in the market for .NET and .NET Framework.

I hope that help especially for the students of Colombia university who asked me to write that article.