wpf IEnumerable Concat 缺失,不包含“Concat”的定义
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33460858/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
IEnumerable Concat Missing, does not contain a definition for 'Concat'
提问by user1034912
I have the following Class which inherits IEnumerable
我有以下继承 IEnumerable 的类
public class LinesEnumerable : IEnumerable<Point>
{
protected readonly IPointSeries _pointSeries;
protected readonly ICoordinateCalculator<double> _xCoordinateCalculator;
protected readonly ICoordinateCalculator<double> _yCoordinateCalculator;
protected readonly bool _isDigitalLine;
/// <summary>
/// Initializes a new instance of the <see cref="LinesEnumerable" /> class.
/// </summary>
/// <param name="pointSeries">The point series.</param>
/// <param name="xCoordinateCalculator">The x coordinate calculator.</param>
/// <param name="yCoordinateCalculator">The y coordinate calculator.</param>
/// <param name="isDigitalLine">if set to <c>true</c> return a digital line .</param>
public LinesEnumerable(IPointSeries pointSeries, ICoordinateCalculator<double> xCoordinateCalculator, ICoordinateCalculator<double> yCoordinateCalculator, bool isDigitalLine)
{
_pointSeries = pointSeries;
_xCoordinateCalculator = xCoordinateCalculator;
_yCoordinateCalculator = yCoordinateCalculator;
_isDigitalLine = isDigitalLine;
}
/// <summary>
/// Returns an enumerator that iterates through a collection.
/// </summary>
/// <returns>
/// An <see cref="T:System.Collections.IEnumerator" /> object that can be used to iterate through the collection.
/// </returns>
public virtual IEnumerator<Point> GetEnumerator()
{
return _isDigitalLine ?
(IEnumerator<Point>)new DigitalLinesIterator(_pointSeries, _xCoordinateCalculator, _yCoordinateCalculator) :
new LinesIterator(_pointSeries, _xCoordinateCalculator, _yCoordinateCalculator);
}
/// <summary>
/// Returns an enumerator that iterates through a collection.
/// </summary>
/// <returns>
/// An <see cref="T:System.Collections.IEnumerator" /> object that can be used to iterate through the collection.
/// </returns>
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
However, when I try to do the following:
但是,当我尝试执行以下操作时:
linesEnumerable = linesEnumerable.Concat(new[] { new Point(viewportWidth, lastYCoordinate) });
it says 'System.Collections.IEnumerable' does not contain a definition for 'Concat' and the best extension method overload 'System.Linq.Queryable.Concat(System.Linq.IQueryable, System.Collections.Generic.IEnumerable)' has some invalid arguments
它说“System.Collections.IEnumerable”不包含“Concat”的定义,最好的扩展方法重载“System.Linq.Queryable.Concat(System.Linq.IQueryable, System.Collections.Generic.IEnumerable)”有一些无效的参数
I already have System.Linq namespace added
我已经添加了 System.Linq 命名空间
Anybody know why this is happening?
有人知道为什么会这样吗?
回答by Josh R
Well this won't help you but this question is the top result when you google the error so I'm going to say what my problem was.
好吧,这对您没有帮助,但是当您使用谷歌搜索错误时,这个问题是最重要的结果,所以我要说我的问题是什么。
I had the following classes:
我有以下课程:
class Group
class Row : Group
class Column : Group
I was trying to call Concat on an IEnumerable<Row>with an IEnumerable<Column>to get an IEnumerable<Group>. This doesn't work because you can't convert the columns to rows. The solution was to cast my IEnumerable<Row>to IEnumerable<Group>.
我试图IEnumerable<Row>用 an调用 ConcatIEnumerable<Column>以获得IEnumerable<Group>. 这不起作用,因为您无法将列转换为行。解决方案是将 my 强制转换IEnumerable<Row>为IEnumerable<Group>.
e.g. rows.Cast<Group>().Concat(columns)
例如 rows.Cast<Group>().Concat(columns)
回答by xr280xr
The compiler will give this error when the two collections are of different types T. For example:
当两个集合的类型不同时,编译器将给出此错误T。例如:
List<int> l1 = new List<int>();
List<string> l2 = new List<string>();
var l3 = l1.Concat(l2);
var l4 = l1.Union(l2);
The Concatand Unioncalls will result in the following compile-time errors respectively:
在Concat和Union通话将分别导致以下编译时错误:
'List' does not contain a definition for 'Concat' and the best extension method overload 'Queryable.Concat(IQueryable, IEnumerable)' requires a receiver of type 'IQueryable'
'List' does not contain a definition for 'Union' and the best extension method overload 'Queryable.Union(IQueryable, IEnumerable)' requires a receiver of type 'IQueryable'
“列表”不包含“Concat”的定义,最佳扩展方法重载“Queryable.Concat(IQueryable, IEnumerable)”需要“IQueryable”类型的接收器
“List”不包含“Union”的定义,最佳扩展方法重载“Queryable.Union(IQueryable, IEnumerable)”需要“IQueryable”类型的接收器
It is confusing because the message is misleading and VS intellisense recognizes the extension methods. The solution is that l1and l2must be lists of the same type T.
这是令人困惑的,因为该消息具有误导性,并且 VS 智能感知识别扩展方法。解决方案是,l1并且l2必须是相同类型的列表T。
回答by Dmitry Dovgopoly
Try to add the following namespaces as well:
尝试添加以下命名空间:
using System.Collections;
using System.Collections.Generic;

