Last post Mar 09, 2013 04:11 PM by Paul Linton
Mar 08, 2013 08:10 AM|waqar1|LINK
If(A && B && C)
If 1st condition is false,, then it would not go to ahead.... it is ok.
Can I trace in visual studion how the if condition is working./??
Mar 08, 2013 08:17 AM|gerrylowry|LINK
"The conditional-AND operator (&&) performs a logical-AND of its
but only evaluates its second operand if necessary."
yes, you can trace in vs ...
Edit # 2:
Look as the IL (Intermediate
Boolean A = false;
Boolean B = false;
Boolean C = false;
if(A && B && C) Console.WriteLine ("all true");
IL_0002: stloc.0 // A
IL_0004: stloc.1 // B
IL_0006: stloc.2 // C
IL_0007: ldloc.0 // A
IL_0008: brfalse.s IL_0013 // .... early exit because of &&
IL_000A: ldloc.1 // B
IL_000B: brfalse.s IL_0013 // .... early exit because of &&
IL_000D: ldloc.2 // C
IL_0011: br.s IL_0014
IL_0015: stloc.3 // CS$4$0000
IL_0016: ldloc.3 // CS$4$0000
IL_0017: brtrue.s IL_0024
IL_0019: ldstr "all true"
IL_001E: call System.Console.WriteLine
N.B.: you need to use the Disassembly Window:
"How to: Use the Disassembly Window"
end edit #2.
walking your code with your debugger:
video, c. 8 minutes:
"How Do I: Step with The Debugger in Visual Studio?"
search videos at Google with debug visual studio 2010 2012
Mar 09, 2013 09:34 AM|markfitzme|LINK
You can debug, insert a breakpoint, and expand the conditions individually. C# (and I believe the other .net languages) have a short-circuit methodology whereby evaluation stops after the first conditions that fails to be met. if A was true, and B was false,
the if would stop evaluating anything after B. It's why you can test for both null and a condition in the same if statement.
If I had a dropdownlist called ddl1 and wanted to select the Text of it's SelectedItem I could do:
if((ddl1.SelectedItem != null) && (ddl.SelectedItem.Text != "All"))
if the property SelectedItem is null, then it stops processing and I don't have to worry about a null exception when accessing the SelectedItem.Text property.
Mar 09, 2013 04:11 PM|Paul Linton|LINK
Use F11 to step-into the execution of a statement. If A,B,C are not simple variables you will see their execution, if it happens.