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

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

主站蜘蛛池模板: 剑川县| 陇川县| 三穗县| 海阳市| 白银市| 梁山县| 纳雍县| 达尔| 九江县| 庄浪县| 内丘县| 鄂尔多斯市| 铁岭市| 五寨县| 肥城市| 桂林市| 锦屏县| 吉首市| 内乡县| 莱西市| 依兰县| 克什克腾旗| 永吉县| 恭城| 钟山县| 芜湖县| 临城县| 加查县| 五莲县| 芜湖县| 达尔| 平顶山市| 诏安县| 满洲里市| 芷江| 烟台市| 澳门| 黔南| 稷山县| 靖边县| 昆山市|