
上QQ阅读APP看书,第一时间看更新
How to do it...
- Open Visual Studio 2017.
- Now open the solution from the previous recipe. Click File | Open | Open Project/Solution, or press Ctrl + Shift + O, and select the Chapter2.Primitives solution.
- Now click on the Chapter2.Library solution label. Click File | Add | New Project.
- In the Add New Project template dialog box, expand the Visual C# node in the left-hand pane.
- Select Windows Classic Desktop and then Console App (.NET Framework) in the right-hand pane:

- Now, in the Name: text box, type Chapter2.Primitives.PrimitivesConsole and leave the Location: text box as it is.

- Click OK.
- After adding the new project, the Solution Explorer (Ctrl + Alt + L) should look like this:

- Click on the References label in the Chapter2.Primitives.PrimitivesConsole project node. Right-click and select Add | Add Reference.
- In the Reference Manager, select Projects in the left-hand pane and check the Chapter2.Primitives.PrimitiveLib in the right-hand pane:

- Click OK to add the reference to the selected project.
- Now, in the newly added console application project, double-click on Program.cs to open the code window.
- Scroll up and add the following using directive:
using Chapter2.Primitives.PrimitiveLib;
- Now, scroll down and in between the curly braces of the Main() method, type the following code:
var myHelper = new Helpers();
var myGrade = myHelper.WhatIsMyGrade(65);
Console.WriteLine($"You are current grade is {myGrade}");
Console.ReadLine();
- Now press F5 to debug the code.
- You should see output like this:

- Now, press any key to exit the console, click just before the Console.ReadLine() line, and press Enter to add some new code.
- Let's type the following code now:
var cm = 15;
var inches = myHelper.CmToInches(cm);
Console.WriteLine($"{cm} centimeters in inches are {inches}");
- Press F5 to see the output and you should see the following:

- Now that we have successfully tested the library, change some values and see how it works.