为什么在以下code断言失败?为什么没有区域 A
和 B
相等?
地区=新区域(新的RectangleF(0.0,0.0,10.0f,10.0f));
区域b =新区域();
b.MakeEmpty();
b.Union(新的RectangleF(0.0,0.0,10.0f,10.0f));
Debug.Assert的(A == B区不等于);
解决方案
这是我所看到的, System.Drawing.Region
不覆盖对象
的实施中的equals()
。因此,你的 ==
呼叫使用的ReferenceEquals
键,只是告诉你 A
和 B
不在同一个对象。
请尝试使用 System.Drawing.Region.Equals(区,图形)
超载而是传递一个图形
目标的背景下,你希望比较这两个地区。
Why does the assertion fail in the following code? Why aren't regions a
and b
equal?
Region a = new Region(new RectangleF(0.0f, 0.0f, 10.0f, 10.0f));
Region b = new Region();
b.MakeEmpty();
b.Union(new RectangleF(0.0f, 0.0f, 10.0f, 10.0f));
Debug.Assert(a == b, "Regions not equal");
解决方案
From what I can see, System.Drawing.Region
does not override Object
's implementation of Equals()
. Therefore your ==
call is using ReferenceEquals
and simply telling you a
and b
are not the same object.
Try using the System.Drawing.Region.Equals(Region, Graphics)
overload instead, passing in a Graphics
object in the context you wish to compare the two regions.
上一篇:不能更改TextView的片段通过setText片段、TextView、setText
下一篇:有没有办法得到一个Android的软键盘与Java的code只有数字(没有小数,空格)?小数、没有办法、空格、键盘