Question: The Sritch statement is a multiple-alternative decision structure. It allows you to test the value of a variable or an expression and then use that
The Sritch statement is a multiple-alternative decision structure. It allows you to test the value of a variable or an expression and then use that value to determine which statement or set of statements to execute. When the Switch statement executes, it compares the value of the testExpression with the values that follow each of the case statements (from top to bottom). When it finds a case value that matches the testExpression's value, the program branches to the case statement. The statements that follow the case statement are executed, until a break statement is encountered. At that point the program jumps out of the switch statement. If the testExpression does not match any of the (cose values, the program branches to the defoult statement and executes the statements that immediately follow it. (Gaddis 250-252) You can use a family of methods in the .NET Framework known as the TryParse methods. With the TryParse methods, you can determine whether a string (such as a control's Text property) contains a value that can be converted to a specific data type before it is converted to that data type. The (TryParse methods do not throw an exception, so you can use them without a try- catch statement (Gaddis 235) Line 5 in the method below is an example of a short-circuit evaluation: if the expression on the left side of the&& operator is false, the expression on the right side is not checked. Because the compound expression is false if only one of the subexpressions is false, it would waste CPU time to check the remaining expression. So, when the && operator finds that the expression on its left is false, it short-circuits and does not evaluate the expression on its right.(Gaddis 226) The Sritch statement is a multiple-alternative decision structure. It allows you to test the value of a variable or an expression and then use that value to determine which statement or set of statements to execute. When the Switch statement executes, it compares the value of the testExpression with the values that follow each of the case statements (from top to bottom). When it finds a case value that matches the testExpression's value, the program branches to the case statement. The statements that follow the case statement are executed, until a break statement is encountered. At that point the program jumps out of the switch statement. If the testExpression does not match any of the (cose values, the program branches to the defoult statement and executes the statements that immediately follow it. (Gaddis 250-252) You can use a family of methods in the .NET Framework known as the TryParse methods. With the TryParse methods, you can determine whether a string (such as a control's Text property) contains a value that can be converted to a specific data type before it is converted to that data type. The (TryParse methods do not throw an exception, so you can use them without a try- catch statement (Gaddis 235) Line 5 in the method below is an example of a short-circuit evaluation: if the expression on the left side of the&& operator is false, the expression on the right side is not checked. Because the compound expression is false if only one of the subexpressions is false, it would waste CPU time to check the remaining expression. So, when the && operator finds that the expression on its left is false, it short-circuits and does not evaluate the expression on its right.(Gaddis 226)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
