- .NET Standard 2.0 Cookbook
- Fiqri Ismail
- 397字
- 2021-06-25 22:11:37
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.
推薦閱讀
- 嵌入式軟件系統(tǒng)測試:基于形式化方法的自動化測試解決方案
- C#編程入門指南(上下冊)
- 實用防銹油配方與制備200例
- C語言最佳實踐
- Practical DevOps
- Python零基礎快樂學習之旅(K12實戰(zhàn)訓練)
- Internet of Things with the Arduino Yún
- aelf區(qū)塊鏈應用架構指南
- 算法訓練營:提高篇(全彩版)
- HTML 5與CSS 3權威指南(第3版·上冊)
- 速學Python:程序設計從入門到進階
- Visual Basic程序設計習題與上機實踐
- 深入實踐DDD:以DSL驅動復雜軟件開發(fā)
- 黑莓(BlackBerry)開發(fā)從入門到精通
- 從零開始學Python大數(shù)據(jù)與量化交易