0

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

3
  • code 0 (0x0) means "there's no more code to run, the program exited successfully". It's not clear what happens or what you expect to happen Commented Feb 8, 2019 at 12:39
  • Is this .NET Core on a Linux machine, or is it .NET Framework on Windows? Commented Feb 8, 2019 at 12:40
  • because your program exited, like the message said... Commented Feb 8, 2019 at 12:42

2 Answers 2

2

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)

Sign up to request clarification or add additional context in comments.

1 Comment

Note that "The program '[4544] forth.dll' has exited with code 0 (0x0)." isn't an error - this is what happens when a command line application finishes and you have not set an exit code
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.