- Beginning C# 7 Hands-On:Advanced Language Features
- Tom Owsiak
- 195字
- 2021-07-02 15:29:19
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;
//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
{
protected void Button1_Click(object sender, EventArgs e)
{
sampLabel.Text = "";//clear label every time
Quad sqr = new Square("John",4);//make a square
Quad rect = new Rectangle("Bob", 2, 5);//make a rectangle
Quad rect2 = new Rectangle("Jerry", 4, 5);//make another rectangle
//stick all these shapes into a list of quads
List<Quad> lst = new List<Quad>(new Quad[] { sqr, rect,rect2});
lst.Sort();//sort the list
if(lst[0] </span>is Square) //if it's asquare
{
//down cast to a square, and call Perimeter on it
sampLabel.Text += ((Square)lst[0]).Perimeter();
}
else if(lst[0] is Rectangle)
{
//if it's a rectangle, down cost to a rectangle,
//and call Perimeter
sampLabel.Text += ((Rectangle)lst[0]).Perimeter();
}
}
}
推薦閱讀
- Learning LibGDX Game Development(Second Edition)
- Designing Machine Learning Systems with Python
- R語言經(jīng)典實(shí)例(原書第2版)
- Beginning Java Data Structures and Algorithms
- 測(cè)試驅(qū)動(dòng)開發(fā):入門、實(shí)戰(zhàn)與進(jìn)階
- C# and .NET Core Test Driven Development
- Regression Analysis with Python
- Python趣味編程與精彩實(shí)例
- PHP+MySQL動(dòng)態(tài)網(wǎng)站開發(fā)從入門到精通(視頻教學(xué)版)
- Python預(yù)測(cè)之美:數(shù)據(jù)分析與算法實(shí)戰(zhàn)(雙色)
- After Effects CC技術(shù)大全
- Docker on Windows
- Java EE基礎(chǔ)實(shí)用教程
- TensorFlow程序設(shè)計(jì)
- Angular Router