我在下面有这段代码——一个将 List 作为输入参数之一的通用方法。在该方法中,是一个 IF/ELSEIF 语句,它运行到一个常见的 LINQ 调用中。请帮帮我,以便所有 IF/ELSEIF 都可以使用 LINQ 调用。
private Boolean filterList<T>(List<T> anyOutdoorSports, int numberOfPartcipants)
{
if (anyOutdoorSports == null){ return false ;}
Boolean _returnValue = false;
if (anyOutdoorSports.GetType() == typeof(List<Swimming>))
{
List<Swimming> Swimming = anyOutdoorSports.Cast<Swimming>().ToList();
if (Swimming.Count > 0)
{
int listCount = (from rca in Swimming
where (rca.RecordFields[numberOfPartcipants].ToString()).StartsWith("stamina")
select rca).Count();
_returnValue = listCount > 0 ? true : false;
}
}
else if (anyOutdoorSports.GetType() == typeof(List<Tennis>))
{
List<Tennis> Tennis = anyOutdoorSports.Cast<Tennis>().ToList();
if (Tennis.Count > 0)
{
int listCount = (from rca in Tennis
where (rca.RecordFields[numberOfPartcipants].ToString()).StartsWith("stamina")
select rca).Count();
_returnValue = listCount > 0 ? true : false;
}
}
else if (anyOutdoorSports.GetType() == typeof(List<Soccer>))
{
List<Soccer> Soccer = anyOutdoorSports.Cast<Soccer>().ToList();
if (Soccer.Count > 0)
{
int listCount = (from rca in Soccer
where (rca.RecordFields[numberOfPartcipants].ToString()).StartsWith("stamina")
select rca).Count();
_returnValue = listCount > 0 ? true : false;
}
}
return _returnValue;
}
感谢所有查看和帮助的人。