The .NET Framework in Overview

C# is a big part of the .NET Framework, and you can run C# programs only on computers that have the .NET Framework installed. As you know, .NET is a huge initiative from Microsoft. It creates an entirely new set of Application Programming Interfaces (APIs). It brings together and improves on many older technologies such as COM+, ASP, XML, OOP, SOAP, WSDL, and so on.

.NET provides the platform on which our applications will run, and that platform runs on top of the underlying operating system. There are many components to the .NET Framework, and from our point of view, here are the most important ones:

  • Four standard programming languages C#, Visual Basic .NET, Managed C++, and J#. (If you include languages from other vendors , there are now more than 25 .NET compliant languages.)

  • The Common Language Runtime (CLR) An object-oriented platform for Windows and Web development. This is what actually runs your code.

  • The Framework Class Library (FCL) An enormous amount of pre-written code that provides built-in support for creating objects such as windows, buttons , list boxes, and thousands more.

The Common Language Runtime is much like the Java virtual machine, which is to say that it provides the environment in which programs execute. The CLR starts programs, checks security issues, manages program execution, assigns memory for programs, and manages that memory through automatic garbage collection , a process that disposes of objects no longer being used.

From a programmer's point of view, the Framework Class Library is a major asset, because it contains tens of thousands of pre-written classes, ready for you to use. You can use those classes to create windows and controls like buttons and check boxes, as well as handle strings, security issues, threads, network communications, Web forms, Windows services, and more. Because all that code is already written for you, you have to use only a few lines to put it all to work.

When you compile a program like the first example into an .EXE file, you're not actually creating the machine code that the computer will run. The .EXE file is actually written in Microsoft Intermediate Language (MSIL, also called IL). .NET programs are compiled into MSIL (much like the bytecodes used in Java), and the CLR converts that MSIL into the actual machine code the computer runs using a just-in-time (JIT) compiler (also like Java).

Take a look at how the first example looks in MSIL. Note that the Main method is marked as the program's entry point:

 
 .method private hidebysig static void Main() cil managed {  .entrypoint  // Code size    11 (0xb)  .maxstack 1  IL_0000: ldstr   "Hello from C#."  IL_0005: call    void [mscorlib]System.Console::WriteLine(string)  IL_000a: ret } // end of method FirstApp::Main 

In fact, there's often more to a program than just the executable code. For example, you can have image files, help files, other code modules, and so on. In .NET, these files can be packaged together into an assembly , which is the .NET unit of deployment. Assemblies appear to the user like single .EXE or .DLL files, but can contain many internal files. They're used for deployment, security (providing boundaries between different assemblies and between their internal files), versioning, and code reuse. The CLR has a great deal of support for manipulating assemblies, and we're going to be working with assemblies starting in Chapter 13, "Understanding C# Assemblies and Security."

CROSS-LANGUAGE PROGRAMMING

Because the MSIL created by a C# program is the same type as, say, that created from a Visual Basic .NET program, the CLR can run either without problem. MSIL makes cross-language programming possible, a major asset of .NET programming. You can develop part of your program in C#, and part in Visual Basic .NET, for example. .NET defines its own types using the Common Type System (CTS), which is common to all .NET programming. The CTS prevents the variables defined in different languages from clashing in your application. Any .NET language must adhere to the Common Language Specification (CLS), which sets up the rules for .NET Framework languages and makes sure they don't clash , even when used in the same program.




Microsoft Visual C#. NET 2003 Kick Start
Microsoft Visual C#.NET 2003 Kick Start
ISBN: 0672325470
EAN: 2147483647
Year: 2002
Pages: 181

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net