Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Using of AndAlso
Message
De
01/09/2011 14:06:55
 
 
À
01/09/2011 13:58:59
John Baird
Coatesville, Pennsylvanie, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01522454
Message ID:
01522519
Vues:
36
>>>>>>>>>Take a look here
>>>>>>>>>http://blogs.lessthandot.com/index.php/DesktopDev/MSTech/andalso-and-orelse
>>>>>>>>
>>>>>>>>Yes, but in the example I gave, And would have done it as well, correct?
>>>>>>>
>>>>>>>If the first condition is false, we don't need to evaluate the second. AndAlso only evaluates the second condition if the first is true. According to the linked article, both conditions will be evaluated if you used And. In other words, it seems we always want to use AndAlso in VB.NET instead of And
>>>>>>
>>>>>>Not *always* :-}
>>>>>>Consider:
Dim i As Integer = 0
>>>>>>While True
>>>>>>	If (i > 10) AndAlso (System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1) > 10) Then
>>>>>>		Exit While
>>>>>>	End If
>>>>>>End While
>>>>>
>>>>>:) Not considering such wicked samples, of course.
>>>>
>>>>I know - just being difficult.
>>>>Same principle applies to 'Or' and 'OrElse' of course.....
>>>
>>>
>>>Just use c# and do away with the troubles... :)
>>
>>But choosing between '&' and '&&' (and '|' and '||') is making the same decision ?
>
>
>I was making a joke.... poorly i guess... :)

Well I must admit that the C# equivalent to my endless loop looks a lot more readable (at least to me):
int i = 0;
            while (true)
            {
                if ((i > 10) && (i++ > 10)) break;
            }
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform