在VB.Net空COALESCE运算符(8) [英] null coalesce operator in VB.Net(8)

查看:135
本文介绍了在VB.Net空COALESCE运算符(8)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我恐怕这是一个愚蠢的问题,但我必须承担,我已经设定VB.Net太长,现在还无法弄清楚如何这样的 C#空合并运算符到VB.Net:

i'm afraid that this is a stupid question, but i must assume that i have programmed VB.Net too long and now can't figure out how to convert this C# null coalescing operator into VB.Net:

if( Convert.ToBoolean(ViewState[tp.UniqueID + "_Display"] ?? true) == false ){}

我知道的 IIF-功能但我不知道如何在这里使用它,如果它给出正确的结果(IIF两个表达式正在评估)。请帮助在黑暗的揭示

I know the IIF-Function but i'm not sure how to use it here and if it gives the correct result(in IIF both expressions are being evaluated). Please help to shed light on the dark.

修改:如果你要看到这个来源:的 forums.asp.net
在那里,你可以看到,生成一个<$ C $的解决方案C>选项严格On不允许从对象到布尔编译器例外隐式转换。

EDIT: if you want to see the source of this: forums.asp.net There you can see a solution that generates a Option Strict On disallows implicit conversions from 'Object' to 'Boolean' compiler exception.

推荐答案

已经有一段时间,但我认为这是你想要什么:

Been a while but I think this is what you want:

CBool(IIf(IsNothing(ViewState(tp.UniqueID + "_Display")), True, False))

修改由Tim( OP):

EDIT by Tim(OP):

这是什么实际上等于C#版本

This is what actually equals the C# version

Not CBool(IIf(IsNothing(ViewState(tp.UniqueID + "_Display")), True, ViewState(tp.UniqueID + "_Display")))

这篇关于在VB.Net空COALESCE运算符(8)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆