CHAPTER 1 THE PHILOSOPHY (Web hosting reseller) OF .NET 25
CHAPTER 1 THE PHILOSOPHY OF .NET 25 // Explicitly list the namespaces used by this file. using System; using System.Drawing; class MyApp { public void DisplayLogo() { // Create a 20_20 pixel bitmap. Bitmap companyLogo = new Bitmap(20, 20); … } } Because your application is referencing System.Drawing, the compiler is able to resolve the Bitmap class as a member of this namespace. If you did not specify the System.Drawing namespace, you would be issued a compiler error. However, you are free to declare variables using a fully qualified name as well: // Not listing System.Drawing namespace! using System; class MyApp { public void DisplayLogo() { // Using fully qualified name. System.Drawing.Bitmap companyLogo = new System.Drawing.Bitmap(20, 20); … } } While defining a type using the fully qualified name provides greater readability, I think you d agree that the C# using keyword reduces keystrokes. In this text, I will avoid the use of fully qualified names (unless there is a definite ambiguity to be resolved) and opt for the simplified approach of the C# using keyword. However, always remember that this technique is simply a shorthand notation for specifying a type s fully qualified name, and each approach results in the exact same underlying CIL (given the fact that CIL code always makes use of fully qualified names) and has no effect on performance or the size of the assembly. Referencing External Assemblies In addition to specifying a namespace via the C# using keyword, you also need to tell the C# compiler the name of the assembly containing the actual CIL definition for the referenced type. As mentioned, many core .NET namespaces live within mscorlib.dll. However, the System.Drawing. Bitmap type is contained within a separate assembly named System.Drawing.dll. A vast majority of the .NET Framework assemblies are located under a specific directory termed the global assembly cache (GAC). On aWindows machine, this can be located under %windir%Assembly, as shown in Figure 1-5.
Go visit our java server pages services for a reliable, lowcost webhost to satisfy all your needs.