代码简要说明如下.该代码需要一堆字符串,并将它们如下所述,中间的if语句决定了其中一个是否连续.问题是If(评估,“”“”)抱怨说它不能是空的,或者必须是一个资源.当评估只是检查一个对象以确保它不是没有和没有的时候,我如何解决这个问题还检查对象中的属性如下:
Dim R as string = stringA & " * sample text" & _ stringB & " * sample text2" & _ stringC & " * sameple text3" & _ If(ApplyValue IsNot Nothing AndAlso ApplyValue.CheckedBox Then,StringD & " * sample text4" & _,NOTHING) stringE & " * sample text5"
VS抱怨applyValue.有任何想法吗?
应该注意的是,我已经尝试了以下内容,看看它是否可以工作,VS正在拒绝它:
Dim y As Double Dim d As String = "string1 *" & _ "string2 *" & _ If(y IsNot Nothing," * sample text4","") & _ "string4 *"
这是什么标记y与:
'IsNot' requires operands that have reference types,but this operand has the value type 'Double'. C:\Users\Skindeep\AppData\Local\Temporary Projects\WindowsApplication1\Form1.vb 13 16 WindowsApplication1
使用IIF三元表达式求值器
原文链接:https://www.f2er.com/vb/255738.htmlDim R as string = stringA & " * sample text" & _ stringB & " * sample text2" & _ stringC & " * sameple text3" & _ IIf(ApplyValue IsNot Nothing AndAlso ApplyValue.CheckedBox,StringD & " * sample text4","") & _ stringE & " * sample text5"
编辑:如果您从2008年起使用VB.NET,您还可以使用
IF(expression,truepart,falsepart)
这更好,因为它提供了短路功能.
Dim R as string = stringA & " * sample text" & _ stringB & " * sample text2" & _ stringC & " * sameple text3" & _ If(ApplyValue IsNot Nothing AndAlso ApplyValue.CheckedBox,"") & _ stringE & " * sample text5"