自动属性/匿名方法/Lamda表达式
protected void Button2_Click(object sender, EventArgs e)
{
List<ShowStuder> list = new List<ShowStuder>();
list.Add(new ShowStuder("小吴", null));
list.Add(new ShowStuder("小曾", 23));
var ShoNave = list.FindAll(s => s.Name == "小曾");
ShoNave.ForEach(j => Response.Write(j.ToString()));
}
public class ShowStuder
{
public string Name { set; get; }
public int? Age { set; get; }
public ShowStuder(string name, int? age)
{
this.Name = name;
this.Age = age;
}
public override string ToString()
{
if (this.Age.HasValue)
return "姓名为:" + Name + " 今年有:" + Age + " 岁";
else
return "姓名为:" + Name + "今年还没有岁数";
}