}

 }

}

Likewise, the following VB.NET code displays the 'Hello, World' string in the console window:

Module Module1

Sub Main()

 Console.WriteLine('Hello, World!')

 Console.ReadLine()

End Sub

End Module

When both programs are compiled, the assembly for each program has an .exe extension. To view the content of each assembly, you can use the ildasm (MSIL Disassembler) tool.

Launch the ildasm tool from the Visual Studio 2008 Command Prompt window (Start→Programs→Microsoft Visual Studio 2008→Visual Studio Tools→Visual Studio 2008 Command Prompt).

The following command uses the ildasm tool to view the assemblies for the C# and VB.NET programs:

C:MSIL>ildasm HelloWorldCS.exe

C:MSIL>ildasm HelloWorldVB.exe

Figure 1-3 shows the content of the C# and VB.NET assemblies, respectively.

Figure 1-3

The Main method of the C# MSIL looks like this:

.method private hidebysig static void Main(string[] args) cil managed {

 .entrypoint

 // Code size 19 (0x13)

 .maxstack 8

 IL_0000: nop

 IL_0001: ldstr 'Hello, World!'

 IL_0006: call void [mscorlib]System.Console::WriteLine(string)

 IL_000b: nop

 IL_000c: call string [mscorlib]System.Console::ReadLine()

 IL_0011: pop

 IL_0012: ret

} // end of method Program::Main

The Main method of the VB.NET MSIL looks very similar to that of the C# program:

.method public static void Main() cil managed {

 .entrypoint

 .custom instance void [mscorlib]System.STAThreadAttribute::.ctor() = ( 01 00 00 00 )

 // Code size 20 (0x14)

 .maxstack 8

 IL_0000: nop

 IL_0001: ldstr 'Hello, World!'

 IL_0006: call void [mscorlib]System.Console::WriteLine(string)

 IL_000b: nop

 IL_000c: call string [mscorlib]System.Console::ReadLine()

 IL_0011: pop

 IL_0012: nop

 IL_0013: ret

} // end of method Module1::Main

The important thing to note here is that regardless of the language you use to develop your .NET applications, all .NET applications are compiled to the MSIL bytecode as this example shows. This means that you can mix and match languages in a .NET project — you can write a component in C# and use VB.NET to derive from it.

Versions of the .NET Framework and Visual Studio

Microsoft officially released the .NET Framework in January 2002. Since then, the .NET Framework has gone through a few iterations, and at the time of writing it stands at version 3.5. While technically you can write .NET applications using a text editor and a compiler, it is always easier to write .NET applications using Visual Studio, the integrated development environment from Microsoft. With Visual Studio, you can use its built-in debugger and support for IntelliSense to effectively and efficiently build .NET applications. The latest version of Visual Studio is Visual Studio 2008.

The following table shows the various versions of the .NET Framework, their release dates, and the versions of Visual Studio that contain them.

Version  Version Number  Release Date  Versions of Visual Studio shipped
1.0 1.0.3705.0 2002-01-05 Visual Studio .NET 2002
1.1 1.1.4322.573 2003-04-01 Visual Studio .NET 2003
2.0 2.0.50727.42 2005-11-07 Visual Studio 2005
3.0 3.0.4506.30 2006-11-06 Shipped with Windows Vista
Вы читаете C# 2008 Programmer's Reference
Добавить отзыв
ВСЕ ОТЗЫВЫ О КНИГЕ В ИЗБРАННОЕ

0

Вы можете отметить интересные вам фрагменты текста, которые будут доступны по уникальной ссылке в адресной строке браузера.

Отметить Добавить цитату
×