ThickBook ThickBook - 1 month ago 10
C# Question

C# beginner help

Can you help in this example? I am a beginner. I am trying to display name from keyboard in console windows.

class Program
{
public static void Main(string[] args)
{
Console.Write("Your Name?: ");
string name = Console.Read();
Console.WriteLine("Welcome {0}", name);
}
}

Jon Jon
Answer

Amongst other things, you probably want to change the middle line of the Main method to

string name = Console.ReadLine();

The Read method returns a single character, whereas the ReadLine method will return the whole line.

Comments