IEnumerable .Select()不工作

Tra*_*acy -1 c# linq

有人能看到我下面的错误吗?第一个命令返回一个空列表.然后第二个命令设置i = 1(这是正确的).

IEnumerable<Demographic> demographics2 = this
  .DemographicRecords
  .Where(item => item.Id == "7633")
  .Select(item => item);

int i = this
  .DemographicRecords
  .Where(item => item.Id == "7633")
  .Count();
Run Code Online (Sandbox Code Playgroud)

D S*_*ley 7

第一个命令返回一个空列表.

不,它返回一个查询.您需要通过循环或调用来处理查询或获取查询的实际结果.类似的评价功能,,等也处理查询,因为它们返回一个具体的结果,而不是另一个查询.foreachToListToArrayAny()Count()Max()

我怀疑你正在调试调试器中的变量.在调试器中查看Linq查询是非常棘手的,因为查询通常只是一些具体集合的包装器.