对于我的生活为什么这个代码产生下面的输出,我可以没有任何意义......C#列表<T> .Find(X => x.Rectangle.Contains(点))失败
我想有是一个错误或什么时使用列表和lambda如果类型公开一个Rectangle属性,并且您使用矩形对象的Contains方法...显式迭代证明true,而列表查找方法失败......
单向
代码
public GridSquare WorldToKeyPadSub(Point location)
{
location = _Map.WorldToClient(location);
GridSquare gs = this.Find(x => x.Rectangle.Contains(location));
GridSquare kp = gs.Find(x => x.Rectangle.Contains(location));
List<GridSquare> list = kp.FindAll(x=>x.Rectangle.Contains(location));
u.dp(list.Count);
GridSquare sub = kp.Find(x => x.Rectangle.Contains(location));
if (sub == null)
{
u.dp("Location to look for " + location);
u.dp("Found Location in grid square " + gs.ToString());
u.dp("grid square bounds " + gs.Rectangle.ToString());
u.dp("Found Location in Keypad " + kp.ToString());
u.dp("key pad bounds " + kp.Rectangle.ToString());
u.dp("Sub Key Pads Print All sub keys in this grid.keypad");
foreach (GridSquare t in kp)
{
u.dp(t.ToString() + " " + t.Rectangle.ToString());
}
u.dp("Sub Key Pads Print Explicit Finds");
foreach (GridSquare t in kp)
{
if (location.X >= t.Location.X
&& location.Y >= t.Location.Y
&& location.X <= t.Location.X + t.Rectangle.Width
&& location.Y <= t.Location.Y + t.Rectangle.Height)
{
u.dp(true);
u.dp(t.ToString() + " " + t.Rectangle.ToString());
}
}
}
return sub;
}
这将产生以下输出...
通知明确矩形(又名手动方法)如何查找包含位置....中房子GDI版本失败方格....
Location to look for {X=1476,Y=1716}
Found Location in grid square GS: 14.3.0.0
grid square bounds {X=1398,Y=1650,Width=100,Height=100}
Found Location in Keypad GS: 14.3.6.0
key pad bounds {X=1465,Y=1683,Width=33,Height=34}
Sub Key Pads Print All sub keys in this grid.keypad
GS: 14.3.6.7 {X=1465,Y=1683,Width=11,Height=11}
GS: 14.3.6.8 {X=1476,Y=1683,Width=11,Height=11}
GS: 14.3.6.9 {X=1487,Y=1683,Width=11,Height=11}
GS: 14.3.6.4 {X=1465,Y=1694,Width=11,Height=11}
GS: 14.3.6.5 {X=1476,Y=1694,Width=11,Height=11}
GS: 14.3.6.6 {X=1487,Y=1694,Width=11,Height=11}
GS: 14.3.6.1 {X=1465,Y=1705,Width=11,Height=11}
GS: 14.3.6.2 {X=1476,Y=1705,Width=11,Height=11}
GS: 14.3.6.3 {X=1487,Y=1705,Width=11,Height=11}
Sub Key Pads Print Explicit Finds
True
GS: 14.3.6.1 {X=1465,Y=1705,Width=11,Height=11}
True
GS: 14.3.6.2 {X=1476,Y=1705,Width=11,Height=11}
A first chance exception of type 'System.NullReferenceException'
我想指出这是非法的......我建议使用单声道来源作为参考。 – Dykam 2010-02-04 06:14:24
我想你的观点是可能的,但是我怀疑链接到莫诺的开罗会对没有使用它的人做任何好处。 – 2010-02-04 14:16:46