- Beginning C# 7 Hands-On:Advanced Language Features
- Tom Owsiak
- 122字
- 2021-07-02 15:29:28
Converting an array to a list of integers
Next, enter the following below this line:
List<int> lst = new int[] { 1, 2, 12, 4, 5, -10, 5, 25, 54 }.ToList();
To make a list of integers, we say lst = new int[]. Then we specify the initializer list and the values shown here. It doesn't matter what values you use. I'll show you some of the methods. Of course, as you can imagine, there are many of them.
Now, note that you could not stop writing this line after the array. If you did, the pop-up tip would say Cannot implicitly convert type 'int[]' System.Collections.Generic.List<int>'; so you have to add .ToList(). You can convert an array to a list of integers.
推薦閱讀
- Visual Basic 6.0程序設計計算機組裝與維修
- Mastering Spring MVC 4
- 區塊鏈:以太坊DApp開發實戰
- PostgreSQL Replication(Second Edition)
- Jupyter數據科學實戰
- Python機器學習:預測分析核心算法
- Mastering Git
- 一本書講透Java線程:原理與實踐
- Python從入門到精通
- Webpack實戰:入門、進階與調優(第2版)
- Mastering VMware Horizon 7(Second Edition)
- C# 7.0本質論
- Wearable:Tech Projects with the Raspberry Pi Zero
- 前端架構設計
- Unity 3D UI Essentials