< Day Day Up > |
Hello, World!By long-standing custom, the first example in any programming language book is the following program. Module HelloWorld Public Sub Main() Console.WriteLine("Hello, world!") Console.ReadLine() End Sub End Module This Visual Basic .NET program simply writes the text Hello, world! to the output window and waits for the user to hit the Return key. It declares a module, HelloWorld , that contains a single method, Main , that is run when the program executes. The Main method calls a system-defined method, WriteLine , on the System.Console class. The WriteLine method takes a string of characters and writes that string to the output window. Then the system-defined method ReadLine on the System.Console class is called. This method waits for the user to enter a string of characters and hit the Return key. The ReadLine call ensures that the output window does not immediately disappear. Although compiling, executing, and debugging a Visual Basic .NET program is not discussed in detail in this book, a few helpful pointers can be discussed. If a machine has Visual Basic .NET installed as part of Visual Studio .NET, the following steps will compile and run the program.
Alternatively, if a machine has only the .NET Framework installed, the following steps will compile and run the program.
Running the Visual Basic .NET compiler causes the source code to be compiled from text into an assembly. An assembly is a file with an EXE or DLL extension that the .NET Framework can load and run. An assembly has a name (in this case, HelloWorld ) that distinguishes it from other assemblies and allows the .NET Framework to identify which assemblies need to be loaded to run a particular program. Inside an assembly are two things created by the compiler intermediate language instructions ( IL ) and metadata . IL is a machine language that the .NET Framework understands and can execute. Metadata is extra information about the program above and beyond what is stored in the IL. Metadata is used by the .NET Framework to ensure that the IL can be executed correctly and securely, and is also used by the .NET Framework Reflection APIs. You can learn more about the internals of the .NET Framework in the book Programming in the .NET Environment , by Damien Watkins, Mark Hammond, and Brad Abrams (Addison-Wesley, 2003). |
< Day Day Up > |