- Beginning C# 7 Hands-On:Advanced Language Features
- Tom Owsiak
- 216字
- 2021-07-02 15:29:25
Converting an array of strings into an array of doubles
Next, let's convert that array of strings into an array of doubles using a different approach; to do this, enter the following below this line:
double[] doubleVals = Array.ConvertAll(vals, new Converter<string, double>(FromStringToDouble));
Notice the ConvertAll method. It's not so easy to use. You need to have an array on which you'll operate. So, in this case, the array is called vals, and then there needs to be something called a converter object (note that the popup shows Converter<TInput, TOutput> converter>). To make a converter, you enter new Converter, and then, in this case, you will transform an array of strings into an array of doubles. So, string is the one you're converting from, and double is the type to which you are converting. This new converter really just wraps a function call, so after that you enter (FromStringToDouble).
The preceding line will accomplish the conversion of the array from one data type to another. Remember, ultimately, it'll grab each value and hit it with Convert.ToDouble(s) from the line near the top.
Next, enter the following:
CompareValues compareValues = (xin, yin) =>
Here, CompareValues is a delegate type—it's like a data type—and we'll name it compareValues, and then you define a new Lambda (xin, yin)=>.
- WildFly:New Features
- Access 2010數據庫基礎與應用項目式教程(第3版)
- UI智能化與前端智能化:工程技術、實現方法與編程思想
- Building Mapping Applications with QGIS
- Blender 3D Incredible Machines
- Visual Basic程序設計習題解答與上機指導
- Hands-On Automation Testing with Java for Beginners
- Visual Basic程序設計上機實驗教程
- 工業機器人離線編程
- Java EE 7 with GlassFish 4 Application Server
- JQuery風暴:完美用戶體驗
- 計算機組裝與維護(第二版)
- Oracle Database XE 11gR2 Jump Start Guide
- JavaScript Concurrency
- jQuery Mobile Web Development Essentials(Second Edition)