
上QQ阅读APP看书,第一时间看更新
How to do it...
- Open Visual Studio 2017.
- 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.
- 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:
- Click OK.
- Now, in the Solution Explorer (or press Ctrl + Alt + L), select Chapter2.Collections. Right-click and select Add | New Project.
- In the Add New Project dialog box, expand the Visual C# node and select .NET Standard in the left-hand pane.
- In the right-hand pane, select Class Library (.NET Standard):

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

- Click OK.
- Now, the Solution Explorer should look like this:

- Click on the Class1.cs and press F2 to rename it. Type LittleShop.cs as the new name.
- Select Yes in the confirmation dialog box for renaming.
- Now double-click on LittleShop.cs to open its code window.
- 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;
- 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;
}
- Let's press Ctrl + Shift + B for a quick build and check for any syntax errors.
- Now type the following code at the end of the using directives at the top of your code window:
using System.Collections;
- 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;
}
- Let's quickly hit a quick Ctrl + B to debug and check for syntax errors.
- Now we are good to go and test the library.