Reputation: 9
I am new to C# and the .NET Code / VSCcode.
Currently using VSCode to run and build C# codes.
I am unable to take user input using Console.ReadLine()
after declaring a particular variable to hold it. The terminal generates this error code at the end of the program:
The program '[4544] forth.dll' has exited with code 0 (0x0).
using System;
namespace forth
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
Console.WriteLine("This is the first program we are trying to build");
var name = Console.ReadLine();
Console.WriteLine("Hello " + name, "you successfully entered a name");
Console.WriteLine("Hello " + name, "you successfully entered a name");
Console.WriteLine("you can press enter to exit the program");
Console.ReadLine();
}
}
}
Output "please enter your name" and displays "Hello + the user's name"
The program should exist afterwards
Upvotes: 0
Views: 303
Reputation: 77285
When you created your project you picked the wrong type. You need to pick "New Console Application".
Right now you are building a library and a library does not have a Main
method. Well, it can have, but it's not called. So create a new project, pick the correct type and copy your code over.
Upvotes: 1
Reputation: 513
Try moving the comma after name to inside the string, and appending the second string to the first:
Console.WriteLine("Hello " + name + ", you successfully entered a name");
At the moment you will be using the WriteLine(string, string) overload, when I think you just want WriteLine(string)
Upvotes: 2