How to do it...

  1. Open Visual Studio 2017.
  2. Click File | New | Project to create a project. 
  3. In the New Project dialog box, expand the Other Project Types node in the left-hand pane and select Visual Studio Solutions. In the right-hand pane, select Blank Solution.
  4. In the Name: textbox, type Chapter4.Delegates and, in the Location: textbox, select a path from the drop-down box or click on the Browse... button to locate a path:
  1. Click OK.
  1. Now, your Solution Explorer (Ctrl + Alt + L) should look like this:
  1. Now, right-click on the Chapter4.Delegates label in the Solution Explorer and select Add | New Project.
  2. In the New Project dialog box, expand the Visual C# node.
  3. Select .NET Standard in the left-hand pane and Class Library (.NET Standard) in the right-hand pane:
  1. Now, in the Name: textbox, type Chapter4.Delegates.DelegateLib. Leave the other defaults as they are and click OK:
  1. Now, the Solution Explorer (Ctrl + Alt + L) should look like this:
  1. Now, select Class1.cs in the Solution Explorer and press F2 to rename the file Calculator.cs.
  2. Answer Yes in the confirmation dialog box that asks to rename the class name as well.
  3. Now, select the Calculators.cs label and double-click on it to open the code window.
  4. Add the following using directive to the top of the code:
      using System.Linq;
  1. Now, scroll down in between the curly brackets of the Calculator class and add the following code:
      public delegate string Message(string msg);
public string AddTwoNumbers(int n1, int n2, Message msg)
{
return msg($"The answer is : {n1 + n2}");
}
  1. Now, next to the end curly bracket of the AddTwoNumbers() method, add the following code:
      public string CountScoresMoreThan80(int[] scores)
{
var count = scores.Where(s => s > 80).Count();

return $"There are {count} scores more than 80";
}
  1. Perform a quick build by pressing Ctrl + Shift + B and confirm that all the syntax is correct.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.226.105