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

Chapter review

For review purposes, 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;
//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 delegate bool Compare(double x, double y);
public delegate double Multiply(double x, double y);
public partial class _Default : System.Web.UI.Page
{
protected void Button1_Click(object sender, EventArgs e)
{
double x = 10, y = 25; //declare two variables
//the two variables are accessible inside the lambda expressions
Compare comp = (a, b) => (a == b);//define comparison lambda
//invoke the lambda in the line below
sampLabel.Text =
$"{x} and {y} are equal is {comp(x, y).ToString().ToLower()}";
//line define a lambda for multiplication
Multiply mult = (a, b) => (a * b);
//invoke the multiplication lambda
sampLabel.Text += $"<br>{x}*{y} is {mult(x, y)}";
//make array of doubles
double[] dubsArray = new double[] { 1, 2, 3, 4, 5 };
//actions encapsulate functions that do not return a value
//but actions can accept arguments to operate on
Action<double> showDouble =
(a) => sampLabel.Text += "&lt;br>" + (a * a);
//it's now possible to perform the action on each d repeatedly
foreach (var d in dubsArray)
{
showDouble(d);
}
}
}
主站蜘蛛池模板: 寿阳县| 镶黄旗| 平南县| 泽库县| 高清| 山阳县| 乌鲁木齐县| 新沂市| 肇源县| 襄汾县| 南开区| 红安县| 灌阳县| 永修县| 万盛区| 太仆寺旗| 酉阳| 巢湖市| 湘乡市| 高碑店市| 洪湖市| 乐山市| 同德县| 剑川县| 定兴县| 大余县| 吐鲁番市| 靖远县| 呼玛县| 桐柏县| 宁陵县| 即墨市| 江永县| 蓬莱市| 肇源县| 临江市| 家居| 遵化市| 新和县| 永仁县| 舞钢市|