2

无论我做什么,我的第一个 Console.Readline 条目都会让我脱离控制台。无论我是在调试还是发布,都会发生这种情况。

我通过了我的 WriteLine

("Which Room Would you like to Trigger? \nRoom 1001 or Room 1002") 

一旦我点击 ReadLine 控制台就会关闭。

我仍在学习 C#,但我从未遇到过 Python raw_input(prompt) 的这个问题,我假设它等同于 C# ReadLine。

我的代码如下。

bool loopChk = true;

      do
      {
        Console.WriteLine("Which Room Would you like to Trigger? \nRoom 1001 or Room 1002");
        string line = Console.ReadLine();
        if (line == "1001")
        {
          await objClient.WritePropertyAsync(fqrs[0], "Present Value", a_bOn ? "on" : "off", CancellationToken.None);
          Console.WriteLine("You have Triggered Room 1001");
        }
        else if (line == "1002")
        {
          await objClient.WritePropertyAsync(fqrs[1], "Present Value", a_bOn ? "on" : "off", CancellationToken.None);
          Console.WriteLine("You have Triggered Room 1002");
        }
        else if (line == "exit")
        {
          break;
        }
      } while (loopChk);
4

1 回答 1

0

试试这个:

string line = null;

do {
    Console.WriteLine("Which Room Would you like to Trigger? \nRoom 1001 or Room 1002");
    line = Console.ReadLine();

    if (line == "1001")
    {
      await objClient.WritePropertyAsync(fqrs[0], "Present Value", a_bOn ? "on" : "off", CancellationToken.None);
      Console.WriteLine("You have Triggered Room 1001");
    }
    else if (line == "1002")
    {
      await objClient.WritePropertyAsync(fqrs[1], "Present Value", a_bOn ? "on" : "off", CancellationToken.None);
      Console.WriteLine("You have Triggered Room 1002");
    }
} while (line != "exit")
于 2015-04-21T04:49:16.547 回答