使用VB.NET IIF我得到的NullReferenceException [英] Using VB.NET IIF I get NullReferenceException
问题描述
我做的一点点调试,所以我想记录的EventArgs值
I am doing a little debugging, and so I want to log the eventArgs value
我有一个简单的线条,基本上不会:
I have a simple line that basically does:
logLine = "e.Value: " + IIf(e.Value Is Nothing, "", e.Value.ToString())
据我所知,IIF函数,如果e.Value为Nothing(空),那么它应该返回空字符串,如果没有它应该返回的值的ToString方式。我,但让一个NullReferenceException。这是没有道理给我。
The way I understand the IIF function, if the e.Value is Nothing (null) then it should return the empty string, if not it should return the .ToString of the value. I am, however getting a NullReferenceException. This doesn't make sense to me.
任何想法的?
推荐答案
IIF 是一个实际功能,所以所有的参数得到评估。该如果的关键字加入到2008年VB.NET提供短路功能,你期待的。
IIf is an actual function, so all arguments get evaluated. The If keyword was added to VB.NET 2008 to provide the short-circuit functionality you're expecting.
尝试
logLine = "e.Value: " + If(e.Value Is Nothing, "", e.Value.ToString())
这篇关于使用VB.NET IIF我得到的NullReferenceException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!