Visual studio 2010 发生事件(生成文本文件)后,如何使我的程序(exe)停止(而不是退出)?
我正在visual studio中创建一个可执行文件 我的代码是这样的:Visual studio 2010 发生事件(生成文本文件)后,如何使我的程序(exe)停止(而不是退出)?,visual-studio-2010,exe,goto,Visual Studio 2010,Exe,Goto,我正在visual studio中创建一个可执行文件 我的代码是这样的: if(condition) goto Step 1 else goto Step 2 Step 1: code Step 2: code 我想这样做,如果步骤1已经运行,那么必须跳过步骤2 应该使用函数吗?在类中,它可以放在两个函数中,并从if-else逻辑调用,或者可以将代码放在if和else之间。如果代码很大,那么最好创建两个函数 If (condition) call function
if(condition)
goto Step 1
else
goto Step 2
Step 1:
code
Step 2:
code
我想这样做,如果步骤1已经运行,那么必须跳过步骤2
应该使用函数吗?在类中,它可以放在两个函数中,并从if-else逻辑调用,或者可以将代码放在if和else之间。如果代码很大,那么最好创建两个函数
If (condition)
call function step1
else
call function step2
or
if (condition)
code...
else
code...
除非你有很好的理由,否则请不要使用goto。在这种情况下,函数几乎可以肯定是更好的。我在你的第二个建议中做到了这一点,但无法使用函数:在C中使用函数比在C中使用函数更复杂。@ABX如果你有问题,请发布你的实际代码。在C中使用函数并不比在C中更复杂。这两种语言都非常简单和基本。更新了答案,并提供了如何在C中创建和调用函数的链接和示例
public void Caller()
{
int numA = 4;
// Call with an int variable.
int productA = Square(numA);
int numB = 32;
// Call with another int variable.
int productB = Square(numB);
// Call with an integer literal.
int productC = Square(12);
// Call with an expression that evaulates to int.
productC = Square(productA * 3);
}
int Square(int i)
{
// Store input argument in a local variable.
int input = i;
return input * input;
}