VB.NET:在 IF 条件中为变量赋值? [英] VB.NET: Assign value to variable inside an IF condition?

查看:29
本文介绍了VB.NET:在 IF 条件中为变量赋值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能在 VB.NET 中为 IF 条件内的变量赋值?

is there any possibility to assign a value to a variable inside an IF condition in VB.NET?

类似的东西:

Dim customer As Customer = Nothing

If IsNothing(customer = GetCustomer(id)) Then
    Return False
End If

谢谢

推荐答案

抱歉,没有.另一方面,它会变得非常混乱,因为 VB.NET 使用相同的运算符进行赋值和相等.

Sorry, no. On the other hand, it would get really confusing, since VB.NET uses the same operator for both assignment and equality.

If a = b Then 'wait, is this an assignment or comparison?!

相反,只需设置变量并进行比较:

Instead, just set the variable and compare:

Dim customer As Customer = Nothing

customer = GetCustomer(id)

If IsNothing(customer) Then
    Return False
End If

这篇关于VB.NET:在 IF 条件中为变量赋值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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