How to use Console.ReadLine() in a project using MonoDevelop under Linux

时间:2018-02-03 08:17:35

标签: c# monodevelop opensuse

I have the following sample project and I use MonoDevelop in OpenSuse. I can build the project, but when I execute it, it does not show any console where I can enter the string. I am aware about people indicating that we should set the Project options to "Run on External Console". That option is enabled, but there is no console appearing when I execute the program under MonoDevelop. Do we have to open a console separately and attach to process, or is there another trick?

using System;
namespace ConsoleReadLine
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            string s = Console.ReadLine ();
            Console.WriteLine (s);
            Console.ReadLine ();
        }
    }
}

1 个答案:

答案 0 :(得分:1)

目前(版本 7.8.4 (build 2)),这在 Linux 上仍然是一个问题。

要解决这个问题,您需要:

  1. 右键单击解决方案(而不是项目),然后选择“选项” enter image description here

  2. 在“运行”中,在“配置”下选择“默认”,勾选“在外部控制台上运行” enter image description here

  3. 点击“确定”,就是这样!

我不知道是否有任何方法可以在系统范围内(即所有解决方案)改变这种行为,但我很想知道。