Chapter 3 Major VB.NET Changes(3)
点击次数:48 次 发布日期:2008-11-06 08:07:06 作者:源代码网
|
源代码网推荐 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. 源代码网推荐 源代码网推荐 源代码网供稿. |
