当前位置:首页 > ASP教程 > 应用技巧

Asp中通过简单的例子理解下ByVal和ByRef的用法

文件名称:

byval.asp

byref.asp

具体代码:

<%
sub testmain()
dim a : a=5
call testby(a)
response.write a
end sub
sub testby(byval t)
t=t+1
end sub
call testmain()
%>

<%
sub testmain()
dim a : a=5
call testby(a)
response.write a
end sub
sub testby(byref t)
t=t+1
end sub
call testmain()
%>

运行结果:

5

6

结    论:

注意:子程序testby(byval t)中t变量声明方式是byval

运行结果子程序没有影响到a的值

注意:子程序testby(byref t)中t变量的声明方式是byref

运行结果a的值通过子程序发生了改变

看完了,上面的比较就知道说明意思了吧。

【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!