-
C#入门经典教程-探讨类型安全
资源介绍
类型安全1
MySchool中添加一个Teacher类
Teacher jacky = new Teacher("成龙龙", 4);
jacky.SayHi();
students.Add(jacky);
能否加入一个Teacher对象?
foreach (Object stuo in students)
{
Student stu = (Student)stuo;
Console.WriteLine(stu.Name);
}
遍历这个集合是否有问题?
演示:MySchool
演示添加对象与遍历
添加正确
遍历时出错