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:
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."
|