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

Chapter review

For review, the complete version of the Default.aspx.cs file for this chapter, including comments, is shown in the following code block:

//using is a directive
//System is a name space
//name space is a collection of features that our needs to run
using System;
using System.Collections.Generic;
using System.Threading;
//public means accessible anywhere
//partial means this class is split over multiple files
//class is a keyword and think of it as the outermost level of grouping
//:System.Web.UI.Page means our page inherits the features of a Page
public partial class _Default : System.Web.UI.Page
{
private void ShowSquare(double x) =>
sampLabel.Text += "<br>" + (x * x);//expression bodied function
protected void Button1_Click(object sender, EventArgs e)
{
//make list of double values
List<double> vals =
new List<double>(new double[] { 1, 2, 4, 5, 6, 8 });
//call ShowSquare on each value inside the list
vals.ForEach(ShowSquare);
sampLabel.Text += "<br>-----------------------------------" ;
//lines 21-24 define an unnamed method, which is applied to each
//value in the list
vals.ForEach(delegate (double x)
{
sampLabel.Text += "<br>" + Math.Pow(x, 3);
});
sampLabel.Text += "<br>-----------------------------------" ;
//lines 28-35 create a thread object, and an unnamed method inside
//it that spawns
//a thread of processing separate from the "main" program
Thread td = new Thread(delegate ()
{
List<double> arrs =
new List<double>(new double[] { 1, 4, 5, 3, 53, 52 });
arrs.Sort();
arrs.ForEach(x => sampLabel.Text += $"<br>{x}");
});
//start the thread
td.Start();
td.Join(); //this is needed to ensure that the thread
//"td" runs, and then joins back to the
//current, main thread, so the program finishes running
}
}
主站蜘蛛池模板: 普安县| 稷山县| 顺义区| 景宁| 林周县| 霍山县| 日喀则市| 延津县| 鹤庆县| 呼和浩特市| 桂阳县| 且末县| 鄂托克前旗| 宁乡县| 都匀市| 保山市| 紫云| 苍溪县| 阳江市| 五原县| 陇西县| 博罗县| 沁阳市| 栾川县| 潍坊市| 龙南县| 通化县| 常熟市| 哈密市| 天全县| 奉贤区| 奎屯市| 九龙坡区| 微山县| 阿图什市| 大新县| 敦化市| 舒兰市| 阿合奇县| 泰和县| 巴南区|