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

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();
}
}
}
主站蜘蛛池模板: 望江县| 易门县| 衡阳市| 潼南县| 永定县| 浪卡子县| 曲水县| 黄石市| 廊坊市| 普安县| 鹰潭市| 库尔勒市| 灵台县| 太仆寺旗| 莱阳市| 特克斯县| 临江市| 四川省| 贵阳市| 广西| 广元市| 屏南县| 昌江| 高安市| 和静县| 龙口市| 麻栗坡县| 山阴县| 东安县| 丹棱县| 南通市| 洞口县| 永福县| 宜川县| 绍兴县| 宜良县| 武乡县| 崇文区| 包头市| 从化市| 德化县|