Introduction to .NET
Introduction
.NET is a general-purpose software development platform, similar to Java..NET is a new framework for programming Windows.The key technologies within .NET are: Common Language Runtime (CLR),Language Interoperability, XML Web Services,ASP.NET, ADO.NET, Assemblies, Application Domain, Code level Security etc.
The languages under.net are c#,vb.net,j#,c++.net,jscript etc. c#(pronounced as csharp) is a one of the most populer languge of .NET.
History of .NET
Bill Gates delivered a keynote at Forum 2000, held June 22, 2000, outlining the .NET 'vision'. The July 2000 PDC had a number of sessions on dotnettechnology, and delegates were given CDs containing a pre-release version of the .NET framework/SDK and Visual Studio.NET.The final version of the 1.0 SDK and runtime was made publicly available around 6pm PST on 15-Jan-2002. At the same time, the final version of Visual Studio.NET was made available to MSDN subscribers.The runtime supports Windows XP, Windows 2000, NT4 SP6a and Windows ME/98. Windows 95 is not supported. Some parts of the framework do not work on all platforms - for example, ASP.NET is only supported on Windows XP and Windows 2000. Windows 98/ME cannot be used for development. IIS is not supported on Windows XP Home Edition, and so cannot be used to host ASP.NET. However, the ASP.NET Web Matrix web server does run on XP Home. The Mono project can implement the .NET framework on Linux.
Main Features of .NET Common Type System: Language interoperability under .NET is possible only when all the languages share a common data type system. For this, common type system (CTS) is introduced. CTS ensures that an
int in C# is same as an
int in VC++. Under CTS, all the classes are derived from the
System.Object class and all the primitive data types are mapped to the structures defined in base class library. CTS also specifies the visibility level (from where the type should be accessible) of data types.
Intermediate Language: A .NET programming language does not compile into executable code; instead it compiles into an intermediate code called Microsoft Intermediate Language (MSIL). IL is a CPU-independent language. The IL code is sent to the CLR that converts the code to machine language using the Just In Time compiler, which is then run on the host machine. Important aspect of IL language is that it provides the hardware abstraction layer. We can view the IL code of our application using the ILDASM tool shipped with Visual Studio.NET.
JIT Compilation: JIT (Just In Time) compiler is a crucial component of .NET framework. The JIT compiler converts IL code into machine code, which is then executed. The JIT compiler does not compile entire code at once because it could hamper the performance of the program. It compiles the code at runtime, at the time it is called. The code that is compiled gets stored until the execution comes to an end. This avoids recompilation of code. The reason why conversion from IL code to machine code takes place at runtime is that, the JIT first gets information of the processor type and convert the IL code so that it would run on that type of processor.
Assemblies: An assembly is a unit containing IL code of a program. It is similar to a DLL file, but difference is that unlike DLL, an assembly is self-describing. Assemblies contain assembly metadata (or manifest) that gives details of the assembly, type metadata describing the types, methods, etc. defined in the assembly and resources.
Garbage Collection: Garbage Collection is a program that is invoked by the CLR to free the memory that is not being used by the application. Because of this technique the programmers no more need to take care of memory leakages, dangling pointers and clean up of memory.
I hope that what we saw above would give you a glimpse of .NET framework.
Hello World in .NET
IF you have Visual studio.NET
- Start Microsoft Visual Studio.NET from ‘Start | Program | Microsoft Visual Studio.NET’ menu option.
- Create a new C# project by selecting ‘File | New | Project’ menu option. A ‘New Project’ dialog would appear. From the ‘New Project’ dialog box select project type as ‘Visual C# Projects’or ‘Visual Basic Projects’.
- Select ‘Console Application’ from the list of Templates.
- Select a location where this project should get saved. Give name to the project as Helloworld. Click the OK button.
- A ‘Class1.cs’ or ‘Class1.vb’ file (cs stands for CSharp) would get created with the skeleton code given below.
IF you don't have Visual studio.NET then save the code as cs(for c#)or vb(for vb.net)
Open command line then compile the file name by
>csc filename.cs (for c#)
>vbc filename.vb (for vb.net)
Csharp Code
using System ;
namespace Helloworld
{ class Class1
{
static void Main ( string[ ] args )
{
Console.WriteLine("Hello World!");
}
}
}
VB.NET Code
Imports System
Namespace Helloworld
Friend Class Class1
Shared Sub Main(ByVal args As String())
Console.WriteLine("Hello World!")
End Sub
End Class
End Namespace
Compile and execute the program by pressing Ctrl + F5(in Visual Studio.NET). The program execution starts from the Main( ) function. Since C# &VB.NET is a pure object-oriented language it does not allow us to create global variables and functions. Instead, all variables and functions including Main( ) should be defined inside a class.
To send output to the screen we have used the WriteLine( ) function. We can display any data type through this function. Since WriteLine( ) belongs to the Console class we have to use the form Console.WriteLine( ) to call it.
To be able to use the Console class in any program we need to import it from a namespace, which has been done in our program through the statement using System. Like the Console class our class is also enclosed in the Helloworld namespace.