“System.Collections.Generic.IEnumerable<decimal>”不包含“ToArray”的定义,并且找不到可接受类型为“System.Collections.Generic.IEnumerable<decimal>”的第一个参数的扩展方法“ToArray” Kevin

在学习MVC3的单元测试的时候碰到一个奇怪的事情:

[TestClass]
public class MyPriceReducerTest
{
[TestMethod]
public void All_Prices_Are_Changed()
{
FakeResponsitory repo = new FakeResponsitory();
decimal reductionAmount = 10;

IEnumerable<decimal> prices = repo.GetProducts().Select(e => e.Price);
decimal[] intialPrices = prices.ToArray();
}
}

其中repo.GetProducts().Select(e=>e.Price) 报错,说是没有该方法

百思不得其解 ,后来对比单元测试项目的引用和项目的引用才发现,少了引用System.Linq

VS2010一般新建项目都会自动引用该引用,不知道为什么单元测试ide项目没有引用,哎,花了好长时间才找到这个错误,

看来还是基础不牢啊!

原文地址:https://www.cnblogs.com/kfx2007/p/2550873.html