C#/ Mono Console.In.ReadToEnd()停止进程

时间:2011-01-16 05:41:50

标签: c# linux mono console

如果我有以下代码:

namespace foo {
 public class FooClass {
  public static void Main (string[] argsRaw) {
   Console.WriteLine(Console.In.ReadToEnd());
  }
 }
}

我运行它,一旦到达流的末尾,进程就会停止。

输出:

(Text of my input stream)
[1]+  Stopped                 bin/Debug/foo.exe

如何让我的程序更像grep,在点击EOF后不会停止?

1 个答案:

答案 0 :(得分:1)

我明白了。

您需要确保Main的返回类型是int。

namespace foo {
    public class FooClass {
        public static int Main (string[] argsRaw) {
            Console.WriteLine(Console.In.ReadToEnd());
            return 0;
        }
    }
}

作品。