Wednesday, April 30, 2008

When discussing about the benefits of .NET Framework the first thing needs to consider is CONSISTENT PROGRAMMING MODEL is one merit of .NET FRAMEWORK.


Different programming for doing the same thing. For example the following code demonstrate how to open a file and write one line message to it using Visual Basic 6.0

Public Sub testFileAccess ()
On Error GoTo handle_Error

‘Use native method to opening and writing to a file….

Dim OutputFile As Long
Open “C:\temp\test.txt” For Output As #outputFile
Print #outputFile, “Hello World”
Close #outputFile

‘Use Microsoft scripting scripting runtime to open and write
‘To the file……………

Dim fso As Object
Set fso=CreateObject (“Scripting.FileSystemObject”)

Dim outputText As TextStream
Set OutputText=fso.CreateTextFile (“c:\temp\test2.txt”)
OutputText.Writeline “Hello World”
Set fso=Nothing
Exit Sub

‘Handle or report error here

End Sub

This code demonstrates that more than one technique available to create and write to a new file. The first method uses Visual Basic’s built-in support; the second method uses Microsoft scripting runtime. C++ also offers more than one way of performing same task. The following is a sample demonstrates how to open a file and write a line to it using c++.


using namespace std:

int main(int argc, char* argv[])
//Using c runtime Library (CRT)………..
FILE *testFile;
If((testFile = fopen ( “c: \\ temp\\test3.txt”, “Wt”))==NULL){
cout<< “Could not open file testfile!” << endl;
return 1;
fprintf(testFile, “Hello world \n”);
//Use standard template library
ofstream outputstream(“c:\\temp\\test4.txt”);
cout<< “Could not open second test file”<< endl;

OutputStream << “Hello World!” << endl;
OutPutStream.close ();
return 0;


What both code listing demonstrate is that when using different programming languages a disparity exists among the techniques that developers use to perform the same task. The difference in techniques comes from how different languages interact with and represent the underlying system that applications rely on, thereby increasing the amount of training developers need. The following code demonstrates how to perform the same task in Visual Basic.NET and Visual C#. NET.

Visual Basic.NET

Imports System.IO

Module Demo

Sub Main ()

Dim OutputFile As StreamWriter=New StreamWriter(“c:\temp\test5.txt”)
OutputFile.WriteLine(“Hello World!.”)
End Sub

Visual C#. NET

using System.IO;
using System.Text;

Class Demo{

static void Main(){

StreamWriter outputfile=new StreamWriter(“c:\\temp\\test6.txt”);
OutputFile.WruteLine(“Hello World”);
The preceding code demonstrates, apart from slight syntactical differences, the technique for writing the file in either language is identical- Both listing use the StreamWriter class to write the “Hello world” message out to the text files. In fact unlike Visual Basic and Visual C++ listings there’s more than one way to do something within the same language, the preceding listing show that there is unified means of accomplishing the same task using the .NET class library.

The .NET class Library is a key component of a .Net framework-it is sometimes reffered to as Base Class Library(BCL) .The .NET Class Library contains 100s of classes you can use for tasks such as the following:

1. Processing XML.
2. Working with data from multiple sources.
3. Debugging your code and working with event logs.
4. Working with data streams and streams.
5. Managing the run-time environment.
6. Developing web services, components, and standard windows applications .
7. Working with application security.
8. working with directory services

The functionality that the .Net class library provides is available to all .net languagesresulting in a consistent object model regardless of the programming language developers use.

No comments: