- 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.
推薦閱讀
- 精通Nginx(第2版)
- Spring Boot開發(fā)與測試實戰(zhàn)
- C#程序設計
- Mastering Apache Spark 2.x(Second Edition)
- Getting Started with Gulp
- Spring技術內(nèi)幕:深入解析Spring架構(gòu)與設計原理(第2版)
- 機器學習微積分一本通(Python版)
- Arduino可穿戴設備開發(fā)
- Building Dynamics CRM 2015 Dashboards with Power BI
- 實驗編程:PsychoPy從入門到精通
- Unity 5 Game Optimization
- Blender 3D Cookbook
- Distributed Computing with Python
- Natural Language Processing with Python Cookbook
- 交互設計語言:與萬物對話的藝術(全兩冊)