- Beginning C# 7 Hands-On:Advanced Language Features
- Tom Owsiak
- 192字
- 2021-07-02 15:29:27
Streamlining writing functions
Within the body, but above the line beginning with protected void Button1_Click..., enter the following:
private void ShowSquare(double x) => sampLabel.Text += "<br>" + (x * x);
Remember, => is an expression member. It's a function. In other words, it takes the form of a Lambda. At the end of the line, we return x * x. As you can see, this is a very streamlined way of writing functions.
Next, we need to add namespaces. So, after using System, enter the following lines:
using System.Collections.Generic; using System.Threading;
Now, within the event for the button, we will place the following code list; so, enter this line between a set of curly braces underneath the line beginning with protected void Button1_Click...:
List<double> vals = new List<double>(new double[] { 1, 2, 4, 5, 6, 8 });
In this line, you are making a new list of double data type and then you will initialize it. You can do this a couple of ways, but you can just write an array and then enter some values. It doesn't really matter what they are. This will make a list of double data types.
- 精通Nginx(第2版)
- PHP+MySQL網(wǎng)站開發(fā)技術(shù)項目式教程(第2版)
- Linux網(wǎng)絡(luò)程序設(shè)計:基于龍芯平臺
- Android 應(yīng)用案例開發(fā)大全(第3版)
- Learning Unity 2D Game Development by Example
- 深入理解Android:Wi-Fi、NFC和GPS卷
- 打開Go語言之門:入門、實戰(zhàn)與進(jìn)階
- Android應(yīng)用開發(fā)實戰(zhàn)
- JavaScript機器人編程指南
- Java Web從入門到精通(第2版)
- 貫通Tomcat開發(fā)
- Java EE架構(gòu)設(shè)計與開發(fā)實踐
- 零基礎(chǔ)學(xué)Java第2版
- 快樂編程:青少年思維訓(xùn)練
- 數(shù)字媒體技術(shù)概論