首页 > 编程 > .NET > 正文

Chapter 3 Major VB.NET Changes(3)

2024-07-10 13:02:35
字体:
来源:转载
供稿:网友
in vb6, you could call this sub in one of two ways:
foo “hello ”
call foo(“hello ”)
in vb.net, you also could call this sub in one of two ways:
foo(“hello ”)
call foo(“hello ”)
the difference, of course, is that the parentheses are always required in the vb.net
calls, even though you aren’t returning anything. the call statement is still sup-ported,
but it is not really necessary.
changes to boolean operators
the and , not , and or operators were to have undergone some changes. microsoft
originally said that the operators would short-circuit, but now they are staying the
way they worked in vb6. this means that in vb.net, as in vb6, if you had two
parts of an and statement and the first failed, vb6 still examined the second part.
examine the following code:
dim x as integer
dim y as integer
x =1
y =0
if x =2 and y =5/y then
...
as a human, you know that the variable x is equal to 1 . therefore, when you look at
the first part of the if statement, you know that x is not equal to 2 , so you would log-ically
think it should quit evaluating the expression. however, vb.net examines the
second part of the expression, so this code would cause a divide-by-zero error.
if you want short-circuiting, vb.net has introduced a couple of new operators:
andalso and orelse . in this case, the following code would not generate an error in
vb.net:
dim x as integer
dim y as integer
x =1
y =0
if x =2 andalso y =5/y then
...
this code does not cause an error; instead, because x is not equal to 2 , vb.net does
not even examine the second condition.
注册会员,创建你的web开发资料库,
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表