VB.NET:在IF条件内为变量赋值吗?

标签 vb.net

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

像这样的东西:

Dim customer As Customer = Nothing

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

谢谢

最佳答案

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

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

相反,只需设置变量并进行比较:
Dim customer As Customer = Nothing

customer = GetCustomer(id)

If IsNothing(customer) Then
    Return False
End If

关于VB.NET:在IF条件内为变量赋值吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3350433/

相关文章:

vb.net - 函数返回字符串或 boolean 值

c# - 将 Console.WriteLine 转换为文本框

vb.net - 使用 inpout32.dll 将 Visual Basic 并行端口应用程序转换为 Delphi

vb.net - 如何避免在 Windows 应用程序的文本框中使用特殊字符

.net - 如何在多个项目中使用我的类(class)?

vb.net - 如何将格式函数从 VB 更新到 VB.NET

vb.net - 如何使用VB 2008调整字体?

c# - 如何将值传递给 asp 后面的代码?

vb.net - 如何访问这个变量?

c# - 调用 Windows 安全对话框(在 C# 或 VB.NET 中)