- Beginning C# 7 Hands-On:Advanced Language Features
- Tom Owsiak
- 321字
- 2021-07-02 15:29:20
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.
- LabVIEW入門與實(shí)戰(zhàn)開發(fā)100例
- C#編程入門指南(上下冊(cè))
- Python網(wǎng)絡(luò)爬蟲從入門到實(shí)踐(第2版)
- 數(shù)據(jù)結(jié)構(gòu)(Python語(yǔ)言描述)(第2版)
- Java Web應(yīng)用開發(fā)技術(shù)與案例教程(第2版)
- Easy Web Development with WaveMaker
- Quarkus實(shí)踐指南:構(gòu)建新一代的Kubernetes原生Java微服務(wù)
- Android 應(yīng)用案例開發(fā)大全(第3版)
- TypeScript項(xiàng)目開發(fā)實(shí)戰(zhàn)
- 用戶體驗(yàn)增長(zhǎng):數(shù)字化·智能化·綠色化
- Learning OpenStack Networking(Neutron)
- PHP 7+MySQL 8動(dòng)態(tài)網(wǎng)站開發(fā)從入門到精通(視頻教學(xué)版)
- Solr Cookbook(Third Edition)
- iPhone應(yīng)用開發(fā)從入門到精通
- Geospatial Development By Example with Python