【发布时间】:2018-01-27 18:57:21
【问题描述】:
我有一个包含一个类的列表,并且有一个名为TransactNo 的整数属性。
在另一个帖子中发现了这个
var list = new List<int>(new[] { 1, 2, 4, 7, 9 });
var result = Enumerable.Range(0, 10).Except(list);
如何在数组或对象列表中使用它?
var list<myclass> obj = new list<myclass>();
var result = Enumerable.Range(obj.transactNo[0],obj.transactNo[100]).Except(obj);
我遇到一个错误
严重性代码描述项目文件行抑制状态 错误 CS1929 '
IEnumerable<int>' 不包含 'Except' 的定义,并且最佳扩展方法重载 'Queryable.Except<<anonymous type: int TransNo>>(IQueryable<<anonymous type: int TransNo>>, IEnumerable<<anonymous type: int TransNo>>)' 需要类型为 'IQueryable<<anonymous type: int TransNo>>' 的接收器
public class myclass
{
public int TransactNo { get; set; }
public string Description { get; set; }
public decimal Amount { get; set; }
}
【问题讨论】:
-
你的myclass怎么样?
-
你添加
using System.Linq了吗? -
当您提供伪代码时,很难知道您的 实际 问题是什么 -
var list<myclass> obj = new list<myclass>();一开始就不起作用,因为 C# 区分大小写并且类是List<T>而不是list<T>。请提供minimal reproducible example。 -
public class myclass { public int TransactNo { get; set; } public string Description { get; set; } public decimal Amount { get; set; } } -
不,不要添加评论。 在问题中添加minimal reproducible example。不仅仅是
myclass类——我们可以尝试编译它。到目前为止,您只提供了 sn-ps。