如何在C#中的控制台应用程序中获取用户输入 [英] how to get user input in a console app in C#

查看:678
本文介绍了如何在C#中的控制台应用程序中获取用户输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在制作一个程序,当你输入命令来运行程序时,它运行程序(它是一种迷你操作系统),我需要帮助来获取用户的输入。这是我的代码:

I have been making a program that, when you enter a command to run a program, it runs the program ( it is a kind of mini OS) and i need help with getting the input by the user. Here is my code:

if (/*put the method for getting the user input here and check if the user has pressed the enter key here*\) {System.Diagnostics.Procces.Start(/*put the file name here*/ );} else (/* if the user has not entered a valid command*\) {Console.WriteLine(" Enter a valid command");}

任何人都可以帮助我吗?

can anyone help me?

推荐答案

谷歌不工作?

http ://msdn.microsoft.com/en-us/library/system.console.readline.aspx [ ^ ]


我同意Wes和其他人,我这样做只是因为它在工作中很安静,没有有趣的阅读材料。



这是你的代码:

I agree with Wes and others and I'm doing this only because it's quiet at work and don't have interesting reading material.

Here is your code:
if(Console.ReadLine() == mydesiredValue)
{
    //Some work is done here
}
else
{
    Console.Write("Your message goes here.");
}



这些东西是在许多初学者教程的第一章中学到的。


This stuff is learned in first chapter of many beginner's tutorials.


hi你好再见


这篇关于如何在C#中的控制台应用程序中获取用户输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆