我有一个IF/ELSE声明,虽然我想知道如果它是真的,如何告诉"其他"部分什么都不做.例如:
if(x == x)
//run calc.exe
else
//DoNothing
Run Code Online (Sandbox Code Playgroud)
或者我写信说,如果我只删除else语句,如果if条件不匹配,它会继续吗?
我有代码读取文件,然后将其转换为字符串,然后将字符串写入新文件,虽然有人可以演示如何将此字符串附加到目标文件(而不是覆盖它)
private static void Ignore()
{
System.IO.StreamReader myFile =
new System.IO.StreamReader("c:\\test.txt");
string myString = myFile.ReadToEnd();
myFile.Close();
Console.WriteLine(myString);
// Write the string to a file.
System.IO.StreamWriter file = new System.IO.StreamWriter("c:\\test2.txt");
file.WriteLine(myString);
file.Close();
}
Run Code Online (Sandbox Code Playgroud) 我在Main()中有一个while循环,它经历了几种方法.虽然一个命名的方法ScanChanges()有一个if/else语句,但在这种情况下if,它必须跳转到Thread.Sleep(10000)(在循环结束时).
static void Main(string[] args)
{
while (true)
{
ChangeFiles();
ScanChanges();
TrimFolder();
TrimFile();
Thread.Sleep(10000);
}
}
private static void ChangeFiles()
{
// code here
}
private static void ScanChanges()
{
}
FileInfo fi = new FileInfo("input.txt");
if (fi.Length > 0)
{
// How to Escape loop??
}
else
{
Process.Start("cmd.exe", @"/c test.exe -f input.txt > output.txt").WaitForExit();
}
Run Code Online (Sandbox Code Playgroud) 我有一个问题,我使用Process.Start来启动可执行文件,虽然可以说:如果input.txt == 0kb什么也不做,否则执行进程?
Process.Start("cmd.exe", @"/c test.exe -f input.txt > output.txt").WaitForExit();
Run Code Online (Sandbox Code Playgroud)