- 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.
推薦閱讀
- Spring+Spring MVC+MyBatis整合開發實戰
- C#應用程序設計教程
- Unity 2D Game Development Cookbook
- NGINX Cookbook
- CoffeeScript Application Development Cookbook
- DB2SQL性能調優秘笈
- SAP Web Dynpro for ABAP開發技術詳解:基礎應用
- Joomla!Search Engine Optimization
- 零基礎學編程系列(全5冊)
- Getting Started with Windows Server Security
- Python程序設計教程
- 人件集:人性化的軟件開發
- 深度學習企業實戰:基于R語言
- Java實踐指南
- Deep Learning with TensorFlow(Second Edition)