【发布时间】:2018-02-23 21:29:44
【问题描述】:
我有这个代码:
string winpath = Environment.GetEnvironmentVariable("C:");
int i = 0;
Console.WriteLine("How much would you like to destroy your pc?");
i = Convert.ToInt32(Console.ReadLine());
int j = 0;
while (j < i)
{
Process.Start(winpath + @"\Windows\System32\calc.exe");
j++;
}
我想让用户选择打开多少个计算器,我输入1,得到一个计算器,输入2,我仍然得到一个计算器,输入3得到一个计算器,输入5得到2个计算器。我也尝试了 for 循环,但结果相同。
【问题讨论】:
-
始终使用
Path.Combine连接您的路径字符串。 -
另外,System32 会在搜索路径上,所以你只需要
Process.Start("calc.exe")。 -
那么您的实际问题是什么?你的代码不符合你的要求,但你没有说什么是“不一致”。
标签: c# for-loop while-loop