课程: Learning C#
今天就学习课程吧!
今天就开通帐号,24,600 门业界名师课程任您挑!
Conditionals with "switch"
- [Instructor] We've already seen how the if-else statement can be used to make logical decisions and execute different code paths based on the result. The switch statement is another way of making decisions and is usually used when the number of decisions gets to the point where an if-else constructs would be just too cumbersome to write and read. So let's open the code for this example. So we have our same variable, theVal from our if-else example, and we're going to take a look at the switch statement. So the switch statement has a basic form that looks like this. I'm going to write switch, and then some parentheses and then the curly braces. So inside the parentheses is the expression whose value that you want to test. And so I'm going to use this integer variable that we used for the if-else example. So I'm going to switch on theVal. And then to handle each of the decision branches, you define individual case labels…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。