开发者

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();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜