C# for Java Programmers

All languages would have a hard time doing their jobs without some form of flow control this was true in Java, and it still holds true in C#. It is likely that you have used the following flow control constructs in your Java programming, so we will discuss them briefly. We will spend more time on statements that did not exist in Java, such as the foreach iteration statement, and the infamous goto.
Branch statements, also known as Conditional statements, permit us to branch our code in a different direction based on a condition. Branch statements in both C# and Java consist of if/else and switch statements.
The if/else construct is the most frequently used flow control statement. It tests a condition and if that condition is true, it executes either the next code statement or several code statements if they are enclosed in curly braces. If the condition does not evaluate to true, then it either skips the code segment, or executes code in an else statement. It is used in C# the same way as it is used in Java. For example:
if(x == 1) System.Console.WriteLine("X is equal to 1.");else System.Console.WriteLine("X is not equal to 1."); It is often common to nest if/else statements as in the following example.
if(x == 1) if(y == 2) System.Console.WriteLine("x = 1, y = 2"); else System.Console.WriteLine("x = 1, y...