linux环境下运行mono project.exe 不支持直接读写终端行,但可以通过管道方式让终端支持行交互。可以直接处理行当Console.ReadLine和Console.WriteLine,详细做法:

点击(此处)折叠或打开

  1. using System;

  2. namespace MonoConsole
    {
        class Program
        {

  3.         static void Main(string[] args)
  4.         {
  5.             string line = string.Empty;
  6.             while (true)
  7.             {
  8.                 line = Console.ReadLine().Trim();
  9.                 if (line == "quit")
  10.                 {
  11.                     break;
  12.                 }
  13.                 Console.WriteLine(line);
  14.             }
  15.         }
  16.     }
  17. }
> mcs project.cs
> mono project.exe | cat
hello world
hello wrold
quit
>
11-08 09:31