我正在使用宇宙做一个简单的操作系统。 我是c#的初学者。 cosmos默认代码中的Run()方法循环直到我退出VMware。但是,一旦我修好了一点,我的程序就会自动退出。我不明白为什么。我试图让它循环。 科斯莫的默认代码之前,我修正:c#运行方法不循环
public class Kernel : Sys.Kernel
{
protected override void BeforeRun()
{
Console.WriteLine("Cosmos booted successfully. Type a line of text to get it echoed back.");
}
protected override void Run()
{
Console.Write("Input: ");
var input = Console.ReadLine();
Console.Write("Text typed: ");
Console.WriteLine(input);
}
}
下面是我的新的run()方法。其他一切都保持不变。
protected override void Run() {
Console.WriteLine("Input:");
String input = Console.ReadLine();
if (input.StartsWith("echo"))
{
var index = input.IndexOf("echo");
var initial = input.Substring(0, index);
var final = input.Substring(index + "echo".Length);
var echoInput = initial + final;
Console.WriteLine(echoInput);
}
}
马可福音嗨,你是什么意思试图让它循环?你到了可以输入输入的地步吗?你是什么意思**我的代码自动退出**所以如果你输入** _ echo这是测试_ **你应该看到** _这是测试_ **在我修复之前在控制台上打印出 – jmesolomon
Run()方法直到我自动退出VMware。但是在我修复之后,只要我输入,VMware就会退出。我没有看到我的字符串打印在控制台上。 –
你可以在'if'语句之后添加'Console.ReadKey()'。这应该保持控制台打开,直到你点击一个键。 – jmesolomon