假设我们有一个类,如:在List<SystemMember> elements
如何通过LINQ使用有序元素填充字符串?
class SystemMember : IEquatable<SystemMember>
{
public int Id;
public string Equation;
public bool Equals(SystemMember other)
{
return other != null && (Id.Equals(other.Id));
}
}
上,我们已经做了
elements = elements.Distinct().OrderBy(e => e.Id).ToList();
IDs
可以1, 2, 4, 6, 9
及其确定。
而且我们想要为该列表中的所有IDs
填充字符串结构,如{first (lovest N)}, {next N}, ... , {last N}
。如何用LINQ做这样的事情?
与SystemMember.Equation – myWallJSON 2013-02-26 21:49:09
填补只是可以肯定:你*** do ***'覆盖'方法'Equals(object)'和'GetHashCode()',不是吗?因为没有'GetHashCode()''.Distinct()'调用将不起作用! – 2013-02-26 21:53:44
Thay在评论tyo后说,没有'GetHashCode()''.Distinct()'调用将无法正常工作?其中interfgace是'GetHashCode()'?简单的'IEquatable'不足以让'.Distinct()'工作吗? –
myWallJSON
2013-02-26 21:55:46