C# logic order and compiler behavior
Posted
by Terrapin
on Stack Overflow
See other posts from Stack Overflow
or by Terrapin
Published on 2008-08-07T20:30:00Z
Indexed on
2010/04/14
22:53 UTC
Read the original article
Hit count: 186
In C#, (and feel free to answer for other languages), what order does the runtime evaluate a logic statement?
Example:
DataTable myDt = new DataTable();
if (myDt != null && myDt.Rows.Count > 0)
{
//do some stuff with myDt
}
Which statement does the runtime evaluate first -
myDt != null
or:
myDt.Rows.Count > 0
?
Is there a time when the compiler would ever evaluate the statement backwards? Perhaps when an "OR" operator is involved?
© Stack Overflow or respective owner