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

Assigning functions to represent the delegate

For the right-hand side, we first need to start assigning the functions that it represents. To do this, we can say the following, for example, below the closed curly brace after this line:

public void FindSum(double x, double y)

Imagine that the first thing you'll do is to find the sum of two values. So, you say, for example, Find Sum and then double x and double y.

Then, you can update the labels; so, enter the following between a set of curly braces below this line:

sampLabel.Text = $"<br>{x}+{y}={x + y}";

Now, you can assign FindSum to <int> in the preceding line. You can set this equal, as follows:

Summarize<double> s = FindSum;

Of course, there are many other operations that you can perform. So, let's take this code: this basic function that adds, and define some other operations. Copy (Ctrl + C) these two lines and paste (Ctrl + V) them down below. This time, change FindSum to FindRatio and basically follow the same plan. We'll apply a += operator to make sure that it's appending. Then, to make a new line, put a <br> tag in there and, instead of x + y, change these to x / y. Of course, here you'd have to ensure that y is not 0. We can figure that out:

public void FindRatio(decimal x, decimal y)
{
sampLabel.Text += $"<br>{x}/{y}={x / y}"; }

Let's do one more. So again, copy these two lines and paste them down below. This time, change FindRatio to FindProduct, which is the result of multiplying two values, and change x / y to x * y.

public void FindProduct(decimal x, decimal y)
{
sampLabel.Text += $"<br>{x}*{y}={x * y}";
}

Reminder: If it's brown (Windows) or orange (Mac) it shows on the screen exactly as it is.

Always remember to put in the <br> tags so that stuff gets pushed down to the next line.
主站蜘蛛池模板: 临清市| 嘉兴市| 石泉县| 天柱县| 客服| 遂昌县| 绩溪县| 仁怀市| 娱乐| 迁安市| 阳泉市| 伊春市| 逊克县| 东乡县| 延寿县| 隆化县| 怀安县| 沁水县| 延川县| 屏山县| 岑溪市| 滁州市| 秦皇岛市| 林州市| 贵定县| 勐海县| 泰和县| 五台县| 贵定县| 桐庐县| 峨山| 永兴县| 涞水县| 正阳县| 偏关县| 祁阳县| 山东省| 礼泉县| 临江市| 通城县| 施甸县|