TAILIEUCHUNG - C# language refference_7

Chapter 8 Statements switch (i) { case 0: CaseZero(); goto case 1; case 1: CaseZeroOrOne(); goto default; default: CaseAny(); break; } Multiple labels are permitted in a switch-section. The example switch (i) { case 0: CaseZero(); break; case 1: CaseOne(); break; case 2: default: CaseTwo(); break; } is legal. The example does not violate the "no fall through" rule because the labels case 2: and default: are part of the same switch-section. The “no fall through” rule prevents a common class of bugs that occur in C and C++ when break statements are accidentally omitted. Also, because of this rule, the switch sections. | Chapter 8 Statements switch i case 0 CaseZero goto case 1 case 1 CaseZeroOrOne goto default default CaseAny break Multiple labels are permitted in a switch-section. The example switch i case 0 CaseZero break case 1 CaseOne break case 2 default CaseTwo break is legal. The example does not violate the no fall through rule because the labels case 2 and default are part of the same switch-section. The no fall through rule prevents a common class of bugs that occur in C and C when break statements are accidentally omitted. Also because of this rule the switch sections of a switch statement can be arbitrarily rearranged without affecting the behavior of the statement. For example the sections of the switch statement above can be reversed without affecting the behavior of the statement switch i default CaseAny break case 1 CaseZeroOrOne goto default case 0 CaseZero goto case 1 The statement list of a switch section typically ends in a break goto case or goto default statement but any construct that renders the end point of the statement list unreachable is permitted. For example a while statement controlled by the boolean expression true is known to never reach its end point. Likewise a throw or return statement always transfer control elsewhere and never reaches its end point. Thus the following example is valid Copyright Microsoft Corporation 1999-2000. All Rights Reserved. 145 C LANGUAGE REFERENCE switch i case 0 while true F case 1 throw new ArgumentException case 2 return The governing type of a switch statement may be the type string. For example void DoCommand string command switch case run DoRun break case save DoSave break case quit DoQuit break default InvalidCommand command break Like the string equality operators the switch statement is case sensitive and will execute a given switch section only if the switch expression string exactly matches a case label constant. As illustrated by the example above a switch statement can be made case .

TỪ KHÓA LIÊN QUAN
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.