加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

使用内联IF语句vb.net

发布时间:2020-12-17 00:06:43 所属栏目:大数据 来源:网络整理
导读:代码简要说明如下.该代码需要一堆字符串,并将它们如下所述,中间的if语句决定了其中一个是否连续.问题是If(评估,“”“”)抱怨说它不能是空的,或者必须是一个资源.当评估只是检查一个对象以确保它不是没有和没有的时候,我如何解决这个问题还检查对象中的属性
代码简要说明如下.该代码需要一堆字符串,并将它们如下所述,中间的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:UsersSkindeepAppDataLocalTemporary ProjectsWindowsApplication1Form1.vb 13  16  WindowsApplication1
使用IIF三元表达式求值器
Dim 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"

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读