.NET Standard 2.0 Cookbook
上QQ阅读APP看书,第一时间看更新

How to do it...

  1. Open Visual Studio 2017.
  2. 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. 
  3. Now click on the Chapter2.Library solution label. Click File | Add | New Project.
  4. In the Add New Project template dialog box, expand the Visual C# node in the left-hand pane. 
  5. Select Windows Classic Desktop and then Console App (.NET Framework) in the right-hand pane:
  1. Now, in the Name: text box, type Chapter2.Primitives.PrimitivesConsole and leave the Location: text box as it is.
  1. Click OK.
  2. After adding the new project, the Solution Explorer (Ctrl + Alt + L) should look like this:
  1. Click on the References label in the Chapter2.Primitives.PrimitivesConsole project node. Right-click and select Add | Add Reference.
  1. In the Reference Manager, select Projects in the left-hand pane and check the Chapter2.Primitives.PrimitiveLib in the right-hand pane:
  1. Click OK to add the reference to the selected project. 
  2. Now, in the newly added console application project, double-click on Program.cs to open the code window.
  3. Scroll up and add the following using directive:
      using Chapter2.Primitives.PrimitiveLib;
  1. 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();
  1. Now press F5 to debug the code. 
  1. You should see output like this: 
  1. Now, press any key to exit the console, click just before the Console.ReadLine() line, and press Enter to add some new code. 
  2. Let's type the following code now: 
      var cm = 15;
var inches = myHelper.CmToInches(cm);
Console.WriteLine($"{cm} centimeters in inches are {inches}");
  1. Press F5 to see the output and you should see the following: 
  1. Now that we have successfully tested the library, change some values and see how it works.