【发布时间】:2020-10-10 17:10:27
【问题描述】:
我尝试了以下一些逻辑,但我正在寻找更通用的解决方案,请帮助我是否有其他方法可以获取对象。
static class FinObj
{
public static ppl Find(List<ppl> obj, string Name)
{
foreach (var item in obj)
{
if (item.Name == Name)
{
return (item);
}
}
return null;
}
}
static void Main(string[] args)
{
student d = FinObj.Find(stuList, "B") as student;
teacher x = FinObj.Find(patientList, "BB") as teacher;
}
【问题讨论】:
标签: c# .net list object generic-programming