- 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();
}
}
}
推薦閱讀
- 大學計算機應用基礎實踐教程
- 圖解Java數據結構與算法(微課視頻版)
- Scratch 3游戲與人工智能編程完全自學教程
- Securing WebLogic Server 12c
- 全棧自動化測試實戰:基于TestNG、HttpClient、Selenium和Appium
- Python之光:Python編程入門與實戰
- Mastering Web Application Development with AngularJS
- Django 3.0入門與實踐
- 零基礎C#學習筆記
- Go語言入門經典
- ROS機器人編程實戰
- Java自然語言處理(原書第2版)
- Building a Media Center with Raspberry Pi
- HTML5 Game Development by Example:Beginner's Guide(Second Edition)
- Cloud Development andDeployment with CloudBees