开发者

C#/Mono Console.In.ReadToEnd() stopping process

开发者 https://www.devze.com 2023-02-04 06:03 出处:网络
If I have the following code: namespace foo { public class FooClass { public static void Main (string[] argsRaw) {

If I have the following code:

namespace foo {
 public class FooClass {
  public static void Main (string[] argsRaw) {
   Console.WriteLine(Console.In.ReadToEnd());
  }
 }
}
开发者_如何学Go

And I run it, process will stop once the end of the stream is reached.

Output:

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

How do I get my program to behave more like grep, which does not stop after hitting EOF?


I figured it out.

You need to make sure that Main's return type is an int.

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

Works.

0

精彩评论

暂无评论...
验证码 换一张
取 消