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

Running the program

What you have here is very sophisticated code. Now crank it up in your browser, and take a look at the results. Enter some values, say 1,5, and -3, and click on the Find Max button. The result is 5, as you can see in Figure 7.2.3:

Figure 7.2.3: Preliminary results of running the program with pure integer values

Next, enter something such as 1.01, 1.02, and 0.9999, and click on the Find Max button. The result is 1.02, as you can see in Figure 7.2.4:

Figure 7.2.4: Results of running the program with extended decimal values

So, the program is working as expected.

Again, to review, because there's a lot of code here, we did the following in this program:

  1. First, we declared a delegate.
  2. Then we declared an expression-bodied member, which, in this context of this code, is a function that's defined essentially with a Lambda.
  3. Next, we made an array of values.
  1. Then we created a line to convert the values from a string type to a double type.
  2. After that, we made an expression-bodied Lambda.
  3. Then we built a function called CompareValuesInList that takes that Lambda as an argument and then also looks at the other values.
  4. Finally, CompareValuesInList is where the magic really happens, because it says that, if the third value is bigger than either of the two first compared, then you return the third value. However, if it's not, then simply return the one that is the bigger of the first two.

I know this doesn't seem like an easy thing to do. I know this because I've done this before. You must absolutely add this level of coding, however. Type it, run it, and process it; then you will develop your understanding quickly enough. These are the fundamentals of making some of this stuff useful.

主站蜘蛛池模板: 嘉峪关市| 邢台市| 遵义市| 麻阳| 威信县| 阳高县| 凤凰县| 安塞县| 兰西县| 绥宁县| 沧源| 江源县| 河南省| 吴川市| 德江县| 南投市| 商河县| 洪江市| 临沧市| 习水县| 锦屏县| 民县| 九江市| 松原市| 刚察县| 孝昌县| 新郑市| 灵台县| 蓬溪县| 锦屏县| 黄浦区| 彰武县| 托克托县| 朝阳县| 深圳市| 平山县| 吉木萨尔县| 焉耆| 德江县| 新巴尔虎左旗| 通化县|