How to read user input in c# console

后端 未结 4 1814
[愿得一人]
[愿得一人] 2021-01-16 11:45

I guess this should be very simple to you guys, but very difficult to me because im new to c#.

I have a simple \"pacient\" class.

public class Pacien         


        
4条回答
  •  Happy的楠姐
    2021-01-16 11:45

    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.

提交回复
热议问题