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

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

主站蜘蛛池模板: 微山县| 新郑市| 永年县| 合山市| 于田县| 正镶白旗| 漯河市| 布拖县| 彭州市| 宝丰县| 赤水市| 云安县| 仁化县| 宝清县| 乌拉特后旗| 琼海市| 神农架林区| 荆州市| 富顺县| 昆明市| 栾川县| 英吉沙县| 巴塘县| 桐庐县| 香格里拉县| 罗山县| 东光县| 双桥区| 昭苏县| 五大连池市| 仙桃市| 苍南县| 洛扎县| 巨鹿县| 嘉义县| 诏安县| 洛南县| 北辰区| 连云港市| 崇左市| 华安县|