官术网_书友最值得收藏!

How to do it...

  1. Open Visual Studio 2017.
  2. Click File | New | Project and, in the New Project template dialog box, select Visual Studio Solutions under the Other Project Types node in the left-hand pane, and then Blank Solution in the right-hand pane.
  3. In the Name: text box, type Chapter2.Collections as the name of the solution. Select a preferred location under the Location: drop-down list or click the Browse... button and select a location. Leave the defaults as is they are:



  1. Click OK
  2. Now, in the Solution Explorer (or press Ctrl + Alt + L), select Chapter2.Collections. Right-click and select Add | New Project.
  3. In the Add New Project dialog box, expand the Visual C# node and select .NET Standard in the left-hand pane. 
  1. In the right-hand pane, select Class Library (.NET Standard):
  1. Now, in the Name: text box type Chapter2.Collections.CollectionsLib and leave the Location: text box, as it is:
  1. Click OK.
  1. Now, the Solution Explorer should look like this:
  1. Click on the Class1.cs and press F2 to rename it. Type LittleShop.cs as the new name. 
  2. Select Yes in the confirmation dialog box for renaming. 
  3. Now double-click on LittleShop.cs to open its code window. 
  4. At the top of the code window, move the cursor (or click the mouse) at the last line of the using directives and add the following using directive: 
      using System.Collections.Generic;
  1. Type the following code in between the curly brackets of the LittleShop class: 
      public List<string> GetFruitsList()
{
var fruitsList = new List<string>();

fruitsList.Add("Apples");
fruitsList.Add("Grapes");
fruitsList.Add("Mangoes");
fruitsList.Add("Oranges");
fruitsList.Add("Pineapples");

return fruitsList;
}
  1. Let's press Ctrl + Shift + B for a quick build and check for any syntax errors. 
  2. Now type the following code at the end of the using directives at the top of your code window: 
      using System.Collections;
  1.  At the end of the GetFruitsList() method, add the following code: 
      public ArrayList GetShopItems()
{
var shopItems = new ArrayList();
shopItems.Add("Fruits");
shopItems.Add("Vegetables");
shopItems.Add("Chocolates");

return shopItems;
}
  1. Let's quickly hit a quick Ctrl + B to debug and check for syntax errors. 
  2. Now we are good to go and test the library. 
主站蜘蛛池模板: 沽源县| 聂荣县| 集安市| 遂平县| 集安市| 新邵县| 固阳县| 内江市| 沧州市| 双牌县| 盖州市| 巧家县| 大丰市| 眉山市| 凤台县| 乌鲁木齐县| 循化| 华亭县| 开原市| 德惠市| 若尔盖县| 荔浦县| 礼泉县| 错那县| 曲松县| 黔东| 淮阳县| 绵阳市| 惠东县| 墨竹工卡县| 磐安县| 恩施市| 重庆市| 凤山县| 昌宁县| 安乡县| 班玛县| 广西| 北京市| 密云县| 黄大仙区|