gpt4 book ai didi

vb.net - vb.net 中的 if 运算符出错

转载 作者:行者123 更新时间:2023-12-02 07:04:22 25 4
gpt4 key购买 nike

我的代码中有一行 notes = If(IsDBNull(notes),"","") 。当我尝试在本地主机上运行它时,

我在第 51 行收到错误:

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30201: Expression expected.

Source Error:



Line 49: End Try
Line 50:
**Line 51: notes = If(IsDBNull(notes),"","")**
Line 52: 'Context.Response.Output.Write("AAAA"+notes+"MMM")
Line 53: if notes.Trim().Equals("TIMEUP") then


Version Information: Microsoft .NET Framework Version:2.0.50727.5466; ASP.NET Version:2.0.50727.5459

但是,当将相同的代码移植到生产环境时,它可以毫无故障地运行,知道为什么吗?

最佳答案

问题是 If-operator是在 VS 2008 中引入的,但您正在编译为 .NET Framework 版本:2.0。

这将在 .NET 2 上编译:

Dim notesObj As Object = IIf(IsDBNull(notes),"","")

区别在于 IIF 返回一个对象,而 If 是强类型的(conditional operator (?) in C#),所以你可以这样写:

Dim notesStr = If(IsDBNull(notes),"","") ' a string '

关于vb.net - vb.net 中的 if 运算符出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14871244/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com