在比较操作C#奇怪的结果 [英] c# Strange result on compare operation
本文介绍了在比较操作C#奇怪的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有我的C#code(asp.net code后面)一个奇怪的行为。我张贴在这里的监视窗口的截图:
I have a strange behavior on my c# code (asp.net code behind). I post here a screenshot of the watch window:
我有一个为空(因为你可以看到)和比较的对象用户:用户== NULL返回false。我不明白为什么!
I have an object user that is null (as you can see) and the compare: user == null returns false. I don't understand why!
是有人在这里可以解释为什么出现这种情况?
Is someone here that can explain why this happens?
推荐答案
那么你可以很容易地编写自己的类,它将使这一结果:
Well you can easily write your own class which would give that result:
public class Evil
{
public static bool operator ==(Evil lhs, Evil rhs)
{
return false;
}
public static bool operator !=(Evil lhs, Evil rhs)
{
return false;
}
}
我们只是猜测,此刻...但是,这解释了症状。
We're only guessing, at the moment... but that explains the symptoms.
(我只是试着重写的ToString,我不能得到所需的输出。)
(I've just tried overriding ToString, and I can't get the desired output.)
这篇关于在比较操作C#奇怪的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文