Đang chuẩn bị liên kết để tải về tài liệu:
Essential C# 3.0 FOR NET FRAMEWORK 3.5 PHẦN 3

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

nó tiến triển dễ dàng vào các góc được biết đến ít hơn các ngôn ngữ, khiến cho này cuốn sách không thể thiếu với bất kỳ mức độ của C # phát triển "Troy Magennis, C # MVP và tác giả của HookedOnLINQ.com". Nếu bạn là người mới đến C #, như tôi, cuốn sách của Mark là một cách tuyệt vời để bắt đầu. | Control Flow Statements Continued 129 jump expression is a jump statement such as a break or goto statement. If the switch statement appears within a loop then continue is also allowed. A switch statement must have at least one case statement or a default statement. In other words switch x is not valid. Listing 3.46 with a switch statement is semantically equivalent to the series of if statements in Listing 3.45. Listing 3.46 Replacing the if Statement with a switch Statement static bool ValidateAndMove int playerPositions int currentPlayer string input bool valid false Check the current player s input. switch input case 1 case 2 case 3 case 4 case 5 case 6 case 7 case 8 case 9 Save move as the player directed. . valid true break case case quit valid true break default If none of the other case statements is encountered then the text is invalid. System.Console.WriteLine nERROR Enter a value from 1-9. Push ENTER to quit break return valid 130 Chapter 3 Operators and Control Flow In Listing 3.46 input is the governing type expression. Since input is a string all of the constants are strings. If the value of input is 1 2 . 9 then the move is valid and you change the appropriate cell to match that of the current user s token X or O . Once execution encounters a break statement it immediately jumps to the statement following the switch statement. The next portion of the switch looks for or quit and sets valid to true if input equals one of these values. Ultimately the default label is executed if no prior case constant was equivalent to the governing type. There are several things to note about the switch statement. Placing nothing within the switch block will generate a compiler warning but the statement will still compile. default does not have to appear last within the switch statement. case statements appearing after default are evaluated. When you use multiple constants for one case statement they should appear consecutively as shown in Listing 3.46. The compiler .

crossorigin="anonymous">
Đã 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.