Invalid cast from List to IEnumerable back to List, why?

后端 未结 5 1272
无人及你
无人及你 2021-01-13 11:02

So basically i have this method.

public List FilterCustomersByStatus(List source, string status)
{
    return (List

        
5条回答
  •  旧巷少年郎
    2021-01-13 11:48

    The Where extension filters and returns IEnumerable hence you need to call .ToList() to convert it back

    public List FilterCustomersByStatus(List source, string status)
    {
        return source.Where(c => c.Status == status).ToList();//This will return a list of type customer
    }
    

提交回复
热议问题