How to read user input in c# console

假如想象 提交于 2019-12-02 07:04:48

One variable named name is not enough if you want to split it up into first and last name as provided in your example.

Console.Write("First name:");
var firstName = Console.ReadLine();
Console.Write("Last name:");
var lastName = Console.ReadLine();

Pacient John = new Pacient(firstName, lastName, new DateTime(1992,12,12) , " 045-999-333", "  example@example.com");
John.Email = "example@example.com";

To print it:

Console.WriteLine("Name: {0} {1}",firstName,lastName);

P.S. Patient is spelled with T in English.

Think you can find all the info you need right here.

string line = Console.ReadLine(); // Read string from console

Tip for the future: you already knew that this was called the console, because you used that word in the question. So looking for 'C# console read text' on Google would be a good way to answer this question yourself. (Note: this is not flaming, just some feedback for the next question)

You can get user input via Console.Read(); you need to get each user input

Console.WriteLine("Enter First Name :");
string FirstName = Console.ReadLine();
causita
 Console.WriteLine("What is your choice?:");
            string line = Console.ReadLine();

            switch (line)

{

case "1": // Do Something
break;

case "2": //Do that
}
 while (line != "9");
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!