官术网_书友最值得收藏!

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)=>.

主站蜘蛛池模板: 青神县| 湘西| 禄劝| 元阳县| 周口市| 婺源县| 和林格尔县| 鄂伦春自治旗| 天台县| 大化| 乡宁县| 尼勒克县| 商水县| 宝鸡市| 陵川县| 庆安县| 章丘市| 宁明县| 阿拉善左旗| 宾阳县| 澳门| 西青区| 五华县| 新建县| 大关县| 藁城市| 方正县| 遂川县| 胶南市| 霍林郭勒市| 调兵山市| 瑞昌市| 宝兴县| 富民县| 桂林市| 响水县| 扬中市| 福贡县| 商河县| 于田县| 广元市|