用户输入C#编码 [英] User input in C# coding

查看:68
本文介绍了用户输入C#编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有兴趣添加"你的名字是什么人" 


然后用户输入他/她的名字代码然后说"你好" (你的名字)"


这是我到目前为止的代码


使用System;

解决方案

简单使用Console.ReadLine。如果你想多次尝试,那么使用循环。

使用System; 

namespace ConsoleApp1
{
class program
{
static void Main(string [] args)
{
Console。 WriteLine("Hello Human,很高兴见到你。");
var name = Console.ReadLine();
if(!string.IsNullOrWhiteSpace(name))
{
Console.WriteLine(


" Hello {name}");
}
Console.ReadKey();
}
}
}

循环

使用System; 

命名空间ConsoleApp1
{
class Program
{
static void Main(string [] args)
{
while( true)
{
Console.WriteLine("Hello Human很高兴见到你。");
string name = Console.ReadLine();
Console.WriteLine("是"+名称+"正确?(y)或者您想要更改它(n)?");
string input = Console.ReadLine();

if(input ==" y")
{
break;
}
}
}
}
}


I a'm interested in adding "What is your name human" 

the user then puts in his/her name the code then says "Hello (your name)"

this is the code I have so far

using System;

解决方案

Simple use Console.ReadLine. If you want multiple attempts then use a loop.

using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello Human it is nice to meet you.");
            var name = Console.ReadLine();
            if (!string.IsNullOrWhiteSpace(name))
            {
                Console.WriteLine(


"Hello {name}"); } Console.ReadKey(); } } }

Loop

using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                Console.WriteLine("Hello Human it is nice to meet you.");
                string name = Console.ReadLine();
                Console.WriteLine("Is " + name + " correct? (y) or would you like to change it (n)?");
                string input = Console.ReadLine();
                
                if (input == "y")
                {
                    break;
                }
            }
        }
    }
}


这篇关于用户输入C#编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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