小编Ben*_*Ben的帖子

如果/ Else声明,怎么说"DoNothing"或"Continue"

我有一个IF/ELSE声明,虽然我想知道如果它是真的,如何告诉"其他"部分什么都不做.例如:

if(x == x) 
 //run calc.exe

else
//DoNothing
Run Code Online (Sandbox Code Playgroud)

或者我写信说,如果我只删除else语句,如果if条件不匹配,它会继续吗?

.net c#

10
推荐指数
1
解决办法
6万
查看次数

C# - 附加文本文件

我有代码读取文件,然后将其转换为字符串,然后将字符串写入新文件,虽然有人可以演示如何将此字符串附加到目标文件(而不是覆盖它)

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)

.net c# windows

10
推荐指数
3
解决办法
2万
查看次数

如何逃避循环

我在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)

.net c# loops

4
推荐指数
1
解决办法
476
查看次数

Process.Start,如果输入文件== 0 kb则不执行任何操作

我有一个问题,我使用Process.Start来启动可执行文件,虽然可以说:如果input.txt == 0kb什么也不做,否则执行进程?

Process.Start("cmd.exe", @"/c test.exe -f input.txt > output.txt").WaitForExit();
Run Code Online (Sandbox Code Playgroud)

.net c#

1
推荐指数
1
解决办法
220
查看次数

标签 统计

.net ×4

c# ×4

loops ×1

windows ×1