Click here to Skip to main content
15,899,013 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
using System;
namespace calling
{
class Program
{
	static int Main(string[] args)
{
	if (args.Length == 0)


    Console.WriteLine("Please enter a name.");
return 1;

}
}
}
/* If I aim at greetings, I failed at making a program that would take the user input into account.*/
/* What shall I change (add)?*/


What I have tried:

If I aim at greetings, I fail at making a program that would take the user input into account.
What shall I change (add)?
Posted
Updated 5-Aug-20 3:59am
v2

Have you considered Console.Readline() Console.ReadLine Method (System) | Microsoft Docs[^]
 
Share this answer
 
It is assumed that you want to call your programme like this: e.g.
C#
calling John

Then you must parse the arguments.
C#
using System;

namespace calling
{
    class Program
    {
        static int Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("Please enter a name.");

                Console.ReadKey();

                return 1;
            }

            Console.WriteLine($"Hello {args[0]}");

            Console.ReadKey();

            return 0;
        }
    }
}


"John" is the first argument thus its index will be 0.

C#
Console.ReadKey();

prevents the application from exiting without you seeing anything.
 
Share this answer
 
v2
Comments
BillWoodruff 5-Aug-20 13:27pm    
+4 Down-vote countered.

Suggestion: use 'ReadLine since 'ReadKey will only accept one key-down.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900