Can you use the ch13_02.dll file in the IDE? Yes. In the IDE, you create a new console project, ch13_05. You then right-click the References node in the Solution Explorer, select the Add Reference menu item, and add a reference to ch13_02.dll. Now you can use the same code as was used in ch13_03.cs to interact with ch13_02.dll in the IDE console project, as you see in Listing 13.5. Listing 13.5 Using a DLL (ch13_05.cs)using System; using MultiModule; namespace ch13_05 { /// <summary> /// Summary description for Class1. /// </summary> class Class1 { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main(string[] args) { ch13_02 stringer = new ch13_02(); stringer.Text = "No Worries!"; Console.WriteLine(stringer.LowerCase()); } } } That's all it takesnow you're using the new DLL in the IDE console application code you see in Listing 13.5. This application runs as before, displaying "No Worries!" in a console window. You can also create DLLs in the IDE, of course. To do that, create a new project, ch13_06, in the IDE, selecting the Class Library icon in the Templates box, as you see in Figure 13.2. Figure 13.2. Creating a new DLL project.
This new project will create a DLL, ch13_06.dll, when you build it. We can make the code in this DLL match the code in our current DLL, ch13_02.dll, by giving the new ch13_06 class a Text property and a LowerCase method, as you see in Listing 13.6. Listing 13.6 Creating a DLL (ch13_06.cs)using System; namespace MultiModule { /// <summary> /// Summary description for Class1. /// </summary> public class ch13_06 { string privateText; public string Text { get { return privateText; } set { privateText = value; } } public string LowerCase() { return privateText.ToLower(); } } } That's all we need; now build ch13_06.dll by choosing Build, Build ch13_06 from the IDE. We can use this new, IDE-built DLL, ch13_06.dll, just as we used our earlier command-linebuilt DLL, ch13_02.dll. To do that, just open the ch13_05 console project in the IDE, add a reference to ch13_06.dll, and use this code: static void Main(string[] args) { ch13_06 stringer = new ch13_06(); stringer.Text = "No Worries!"; Console.WriteLine(stringer.LowerCase()); } So far, the assemblies we've been creating are private assemblies , used by only one application. Even the DLLs we've created are intended to be stored in an application's directory structure and used by only one application. But you can also create shared assemblies, which can be used by multiple applications. |