Free mag vol1 | Page 580

CHAPTER 14  BUILDING AND CONFIGURING CLASS LIBRARIES As explained in the next chapter, an assembly’s metadata is a very important element of the .NET platform, and serves as the backbone for numerous technologies (object serialization, late binding, extendable applications, etc.). In any case, now that you have looked inside the CarLibrary.dll assembly, you can build some client applications that make use of your types.  Source Code The CarLibrary project is located under the Chapter 14 subdirectory. Building a C# Client Application Because each of the CarLibrary types has been declared using the public keyword, other .NET applications are able to use them as well. Recall that you may also define types using the C# internal keyword (in fact, this is the default C# access mode). Internal types can be used only by the assembly in which they are defined. External clients can neither see nor create types marked with the internal keyword. To use your library’s functionality, create a new C# Console Application project named CSharpCarClient. After you have done so, set a reference to CarLibrary.dll using the Browse node of the Add Reference dialog box (if you compiled CarLibrary.dll using Visual Studio, your assembly is located under the \bin\Debug subdirectory of the CarLibrary project folder). At this point, you can build your client application to make use of the external types. Update your initial C# file as follows: using using using using using System; System.Collections.Generic; System.Linq; System.Text; System.Threading.Tasks; // Don't forget to import the CarLibrary namespace! using CarLibrary; namespace CSharpCarClient { public class Program { static void Main(string[] args) { Console.WriteLine("***** C# CarLibrary Client App *****"); // Make a sports car. SportsCar viper = new SportsCar("Viper", 240, 40); viper.TurboBoost(); // Make a minivan. MiniVan mv = new MiniVan(); mv.TurboBoost(); Console.WriteLine("Done. Press any key to terminate"); Console.ReadLine(); } 522