对于下面的代码
public struct Person
{
public int ID;
public static bool operator ==(Person a, Person b) { return a.Equals(b); }
public static bool operator !=(Person a, Person b) { return !a.Equals(b); }
}
Run Code Online (Sandbox Code Playgroud)
为什么编译器会给我这些警告?
没有定义下面的方法有什么问题?
warning CS0660: 'Person' defines operator == or operator != but
does not override Object.Equals(object o)
warning CS0661: 'Person' defines operator == or operator != but
does not override Object.GetHashCode()
Run Code Online (Sandbox Code Playgroud) 我使用kendo网格来显示一组记录.但是现在我想使用Aggregates属性对列进行分组并对列执行某些聚合函数.
根据以下文档,我可以在单个列上应用分组,但我想对多列进行分组 http://demos.telerik.com/kendo-ui/grid/aggregates
请建议我如何实现它.
谢谢
我一直试图使我的相等定义工作,但发现IEqualityComparer似乎无法正常工作.
我的课:
public class DBTileSimple
{
public int X;
public int Y;
public int Zoom;
public DBTileSimple(int x, int y, int z)
{
X = x;
Y = y;
Zoom = z;
}
}
Run Code Online (Sandbox Code Playgroud)
测试IEqualityComparer,因此对于任何对象都应该是相同的:
public class TileComparer : IEqualityComparer<DBTileSimple>
{
public bool Equals(DBTileSimple x, DBTileSimple y)
{
return true;
}
public int GetHashCode(DBTileSimple obj)
{
return 1;
}
}
Run Code Online (Sandbox Code Playgroud)
结果:
DBTileSimple t1 = new DBTileSimple(10, 20, 17);
DBTileSimple t2 = new DBTileSimple(10, 20, 17);
Log.Info("t1 and t2 = " …
Run Code Online (Sandbox Code Playgroud)