我找不到键绑定来扩展switch中的所有可能情况,例如.有了enum参数的开关,在Borland C++中我用TAB键做这个,同时选择了开关代码.
我想在Visual Studio 2010中执行此操作.
谁能帮我?
keyboard-shortcuts visual-studio-2010 switch-statement visual-studio
以下示例是http://php.net/manual/de/control-structures.switch.php中的一个例子.
<?php
$totaltime = 0;
switch ($totaltime) {
case ($totaltime < 1):
echo "That was fast!";
break;
case ($totaltime > 1):
echo "Not fast!";
break;
case ($totaltime > 10):
echo "That's slooooow";
break;
}
?>
Run Code Online (Sandbox Code Playgroud)
我期待结果为"那很快".但实际结果是"不快!".如果有人可以解释我为什么会很好吗?
但是,如果我添加另一个案例,case 0: echo "That was super fast!".那么它正在回应正确.即"那太快了!".请帮我看看如何使用条件开关语句.
编辑:-
谢谢大家的回复.我能够通过modifyong开关($ totaltime)来切换上述问题来切换(1)
我正在将一些VB.NET代码转换为C#,因为我对它更熟悉,它可以帮助我更快地解决问题.但是,我遇到了这个代码,这不是VB.NET中的错误 - 但将其转换为C#会产生编译器错误.
Select Case name
Case "FSTF"
.....
Case "FSTF"
.....
End Select
Run Code Online (Sandbox Code Playgroud)
switch(name) {
case "FSTF":
....;
break;
case "FSTF":
....;
break;
}
Run Code Online (Sandbox Code Playgroud)
错误是:
Label'case"FSTF":'已经出现在这个switch语句中.
这里的解决方案是什么 - 这是否意味着在VB.NET代码中,第二个case语句只是一个虚拟 - 或者第一个是假的?
我想使用Java 1.7中的switch语句,它也允许switch(someString).但是,如果我将java编译器更改为1.7,则项目会中断,我要么必须返回1.5或使用android tools-> fix project.
在android开发中有没有办法在字符串中使用开关?
我想基于我从查询字符串创建的数组创建一个Javascript开关.我不知道该怎么办.
假设我有一个这样的数组:
var myArray = ("#general","#controlpanel","#database");
Run Code Online (Sandbox Code Playgroud)
我想创造这个......
switch(target){
case "#general":
$("#general").show();
$("#controlpanel, #database").hide();
break;
case "#controlpanel":
$("#controlpanel").show();
$("#general, #database").hide();
break;
case "#database":
$("#database").show();
$("#general, #controlpanel").hide();
break;
}
Run Code Online (Sandbox Code Playgroud)
myArray可以包含任意数量的元素,因此我希望根据数组的长度动态创建开关.的default情况下,将永远是第一选择.
该数组是从带有正则表达式的location.href创建的,仅提取我需要的内容.
非常感谢!
在考虑具有enum和int作为case参数的switch案例的性能时,最好使用哪个代码片段:
一个.
switch ((ToolbarButton)BtnId)
{
case ToolbarButton.SHOWPROPERTYDIALOG:
OnShowProperties();
break;
case ToolbarButton.MOVETOFIRST:
OnFirstMessage();
break;
case ToolbarButton.MOVETOLAST:
OnLastMessage();
break;
}
Run Code Online (Sandbox Code Playgroud)
B.
switch (BtnId)
{
case (int)ToolbarButton.SHOWPROPERTYDIALOG:
OnShowProperties();
break;
case (int)ToolbarButton.MOVETOFIRST:
OnFirstMessage();
break;
case (int)ToolbarButton.MOVETOLAST:
OnLastMessage();
break;
}
Run Code Online (Sandbox Code Playgroud) 在昨晚阅读了一些SCJP认证后,我开始考虑切换语句以及如何评估表达式,我对某些事情感到有些困惑.
Java不会让你打开布尔值,所以以下内容不会编译:
public static void switchOnBoolean(boolean theBool)
{
System.out.println("\n\nAssessing boolean :" + theBool);
// line below won't compile, since booleans are not valid for the switch statement
switch(theBool)
{
case true:
{
System.out.println("The boolean was true");
break;
}
case false:
{
System.out.println("The boolean was false");
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是,如果您尝试在case块中使用求值为布尔值的表达式,编译器将不会抱怨,例如:
public static void switchOnChar(char theChar)
{
System.out.println("\n\nAssessing char : " + theChar);
switch(theChar)
{
case 'a':
{
System.out.println("The char was a");
break;
}
case 'b':
{
System.out.println("The char was b");
break; …Run Code Online (Sandbox Code Playgroud) 该计划的目的是让用户输入三个考试成绩,并将其平均成绩和字母成绩返回给他们.
它当前编写的方式给出了'public static String getLetterGrade ..'行的错误,我不知道为什么会这样.
public class GradeProblem
{
public static void main(String[] args)
{
char letterGrade;
String exam1, exam2, exam3;
double exam1Score, exam2Score, exam3Score, average;
exam1 = JOptionPane.showInputDialog(null, "Enter your score for Exam 1: ");
exam1Score = Double.parseDouble(exam1.substring(0,2));
int intExam1Score = (int)exam1Score;
exam2 = JOptionPane.showInputDialog(null, "Enter your score for Exam 2: ");
exam2Score = Double.parseDouble(exam2.substring(0,2));
int intExam2Score = (int)exam2Score;
exam3 = JOptionPane.showInputDialog(null, "Enter your score for Exam 3: ");
exam3Score = Double.parseDouble(exam3.substring(0,2));
int intExam3Score = (int)exam3Score;
average = …Run Code Online (Sandbox Code Playgroud) 我知道路由器使用NAT来转换我们从ISP获得的公共IP来说300个本地IP.交换机是否执行相同的功能?如果没有,它有什么不同?
我是R编程的新手.我不知道是否可以将switch语句用于数值对象.
这是我的代码,
myfunction <- function() {
x <- 10
switch(x,
1={
print("one")
},
2={
print("two")
},
3={
print("three")
},
{
print("default") #Edited one..
}
)
}
Run Code Online (Sandbox Code Playgroud)
我收到了这个错误,
test.R:4:18: unexpected '='
3: switch(x,
4: 1=
^
Run Code Online (Sandbox Code Playgroud)
请帮我解决这个问题.
switch-statement ×10
java ×3
c# ×2
android ×1
arrays ×1
casting ×1
enums ×1
identifier ×1
ip ×1
java-6 ×1
javascript ×1
jquery ×1
nat ×1
networking ×1
ocpjp ×1
php ×1
r ×1
router ×1
scjp ×1
vb.net ×1
vb.net-to-c# ×1