///
/// 车站信息类 class
///
public class Station
{
///
/// 编号
///
public int Id { get; set; } = 0;
///
/// 车站名
///
public string Name { get; set; } = string.Empty;
public Station(int id, string name)
{
this.Id = id;
this.Name = name;
}
}
// 列表的初值
List
new Station(1,"北京"),
new Station(2,"石家庄"),
new Station(3,"香河"),
new Station(4,"唐山"),
new Station(5,"北戴河"),
new Station(6,"秦皇岛"),
new Station(7,"廊坊"),
new Station(8,"天津"),
};
///
/// 《小白学程序》第七课:列表(List)应用之二————编制高铁车次信息表
///
///
///
private void button7_Click(object sender, EventArgs e)
{
// #1 创建列表(列车车次信息)
List
// #2 添加节点(车站信息)
G103.Add(stations[0]);
G103.Add(stations[2]);
G103.Add(stations[3]);
G103.Add(stations[4]);
G103.Add(stations[5]);
// #3 输出车次信息
StringBuilder sb = new StringBuilder();
sb.AppendLine("1 去程(正向)
");
foreach (Station s in G103)
{
sb.AppendLine(s.Id + " " + s.Name + "
");
}
sb.AppendLine("
");
// #4 返程(列表的反向)
G103.Reverse();
List
sb.AppendLine("2 返程(反向)
");
foreach (Station s in G103)
{
sb.AppendLine(s.Id + " " + s.Name + "
");
}
webBrowser1.DocumentText = sb.ToString();
}
///
/// 车站信息类 class
///
public class Station
{
///
/// 编号
///
public int Id { get; set; } = 0;
///
/// 车站名
///
public string Name { get; set; } = string.Empty;
public Station(int id, string name)
{
this.Id = id;
this.Name = name;
}
}
// 列表的初值
List stations = new List() {
new Station(1,"北京"),
new Station(2,"石家庄"),
new Station(3,"香河"),
new Station(4,"唐山"),
new Station(5,"北戴河"),
new Station(6,"秦皇岛"),
new Station(7,"廊坊"),
new Station(8,"天津"),
};
///
/// 《小白学程序》第七课:列表(List)应用之二————编制高铁车次信息表
///
///
///
private void button7_Click(object sender, EventArgs e)
{
// #1 创建列表(列车车次信息)
List G103 = new List();
// #2 添加节点(车站信息)
G103.Add(stations[0]);
G103.Add(stations[2]);
G103.Add(stations[3]);
G103.Add(stations[4]);
G103.Add(stations[5]);
// #3 输出车次信息
StringBuilder sb = new StringBuilder();
sb.AppendLine("1 去程(正向)
");
foreach (Station s in G103)
{
sb.AppendLine(s.Id + " " + s.Name + "
");
}
sb.AppendLine("
");
// #4 返程(列表的反向)
G103.Reverse();
List G104 = G103;
sb.AppendLine("2 返程(反向)
");
foreach (Station s in G103)
{
sb.AppendLine(s.Id + " " + s.Name + "
");
}
webBrowser1.DocumentText = sb.ToString();
}
你非常幸运读到的是第一本真正的程序教程。