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

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.

主站蜘蛛池模板: 乐清市| 桃源县| 新巴尔虎右旗| 于都县| 巴楚县| 樟树市| 中宁县| 石家庄市| 二连浩特市| 来凤县| 新蔡县| 乐山市| 德格县| 策勒县| 鄯善县| 河北区| 扎兰屯市| 庆云县| 沙河市| 山阳县| 昭平县| 荆州市| 兰考县| 哈尔滨市| 三明市| 高邮市| 永安市| 邢台市| 犍为县| 牙克石市| 关岭| 丘北县| 中山市| 遂宁市| 宁化县| 正宁县| 南阳市| 正安县| 长宁区| 娄底市| 柯坪县|