首页 > 解决方案 > 使用 linq 查询接收修改后的列表>

问题描述

你知道为什么这不起作用吗?

List<Tuple<DateTime, DateTime, double, double>> 
   newlist = from a in this.EmployeeActivityBook
             where a.Item1 >= start && a.Item1 <= end
             select a;

我收到此错误:

错误

标签: c#linq

解决方案


根据您的错误,您当前正在返回 aIEnumerable<T>而不是 a 。List<T>

您只需要调用.ToList()您的查询。

List<Tuple<DateTime,DateTime,double,double>> newlist = 
    (from a in this.EmployeeActivityBook
     where a.Item1 >= start && a.Item1 <= end
     select a).ToList();

推荐阅读