欢迎光临
我们一直在努力

调用另外一个同名的重载函数漏掉括号出现的严重问题-.NET教程,评论及其它

建站超值云服务器,限时71元/月

我的asp.net不能调试了,由于只是改一个页面,觉的不调试也行吧。仔细检查一下代码就可以了。

可是今天碰到的问题实在是没有检查出来,后来把代码拷贝到笔记本上调试,单步跟踪一下就找出问题来了!

public function getinsertsql() as string

dim strsql as string

strsql = string.format("insert into {0}(inputid,itemid, 数据) values({1},{2},{3});", _tabledata, _reportid, _itemid, _value)

return strsql

end function

public function getinsertsql(byval ddl as dropdownlist) as string

if ddl.items.count = 0 then

return getinsertsql 这里少了括号,应该是return getinsertsql()

因为在vb.net中函数名代表要返回的对象,编译不会出现错误。

如果是直接用getinsertsql的话是个nothing

如果是getinsertsql()表示调用上面的重载函数getinsertsql(),这样才是正确的

可以这样理解: 系统隐式的声明了一个这样的变量,变量名是函数名,类型是函数的返回类型

end if

dim strsql as string = ""

dim v as double

dim sel as string = ddl.selectedvalue

for each item as listitem in ddl.items

v = iif(item.value = sel, _value, 0)

strsql &= string.format("insert into {0}(inputid,itemid,数据,版种) values({1},{2},{3},{4});", _tabledata, _reportid, _itemid, v, item.text.trim())

next

return strsql

end function

真是个很隐蔽的错误,以后要注意了,括号自己加上的好(以前都是vb.net自动加上括号的)

对于这样的问题,编译器应该提出警告才对,或者当取消用函数名来代表返回值。

虽然msdn是这样赞美的:

将返回值分配给函数名的优点是,直到程序遇到 exit function 或 end function 语句时函数才返回控制。这样就可以先分配一个初步的值,以后如有必要再进行调整。

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 调用另外一个同名的重载函数漏掉括号出现的严重问题-.NET教程,评论及其它
分享到: 更多 (0)

相关推荐

  • 暂无文章