开发者

LINQ Convert and Filter List Part 2

开发者 https://www.devze.com 2023-04-11 00:23 出处:网络
Would like to both filter and convert a List. Is this the proper syntax?Filter on type and property. FieldDefEnum开发者_运维问答1 : FieldDef

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

精彩评论

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