LINQ Convert and Filter List Part 2
Would like to both filter and convert a List. Is this the proper syntax? Filter on type and property.
FieldDefEnum开发者_运维问答1 : FieldDef
List<FileDef> fieldDefs
public List<FieldDefEnum1> FieldDefsEnum1
{
get
{
return FieldDefs.OfType<FieldDefEnum1>().ToList().Where(fd => fd.SysCus == enumSysCus.Cus).ToList();
}
}
This will work fine but you have redundant .ToList()
in the middle that will break deferred execution. try this:
FieldDefs.OfType<FieldDefEnum1>().Where(fd => fd.SysCus == enumSysCus.Cus).ToList();
精彩评论