假設我們有一個類,如:在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