为什么“\n”是真的不可以比较吗?
请看这里的场景: http://social.microsoft.com/Forums/getfile/3600/ 为什么不匹配?
Look at the sceene here , please:
http://social.microsoft.com/Forums/getfile/3600/
why it's not matching?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编辑:好的,现在我们知道它是
XmlReader。 Value
,它确实返回一个字符串,这绝对不是问题。我将把之前的答案留在下面以供将来参考。我的猜测是,有一些“奇怪”的 Unicode 字符没有显示在调试器中......或者监视窗口的行为很奇怪。观察
xml.Value.ToCharArray()
将有助于显示这一点。(顺便说一句,给
Dictionary<,>
参数命名list
非常令人困惑......)编辑:此外,使用支撑和缩进也会 让您的代码更易于理解...
我们目前无法确定,但我的猜测是
Value
属性的类型为 <代码>对象,而不是字符串
。这意味着==
和!=
执行引用比较(记住,运算符是重载,而不是覆盖)。您想要以下多态行为:或者如果
xml.Value
可以合法地为 null:EDIT: Okay, now we know it's
XmlReader.Value
, which does return a string, that's definitely not the problem. I'll leave the previous answer below for future reference.My guess is that there are some "odd" Unicode characters which don't show up in the debugger... or that the watch window is behaving strangely. Putting a watch on
xml.Value.ToCharArray()
would help to show that.(As an aside, giving a
Dictionary<,>
parameter the namelist
is very confusing...)EDIT: Additionally, using bracing and indentation would also make your code easier to follow...
We can't tell for sure at the moment, but my guess is that the
Value
property is of typeobject
, notstring
. That means that==
and!=
perform reference comparisons (operators are overloaded, not overridden, remember). You want the polymorphic behaviour of:or if
xml.Value
can legitimately be null: