0

nice to meet you. I'm new user of C# Language, and studying microsoft C# tutorial. Link : https://msdn.microsoft.com/en-us/library/aa288436(v=vs.71).aspx

But I have a problem in the first lesson. Link : https://msdn.microsoft.com/en-us/library/aa288463(v=vs.71).aspx

// Hello3.cs
// arguments: A B C D
using System;

public class Hello3
{
   public static void Main(string[] args)
   {
      Console.WriteLine("Hello, World!");
      Console.WriteLine("You entered the following {0} command line arguments:", args.Length );
      for (int i=0; i < args.Length; i++)
      {
         Console.WriteLine("{0}", args[i]); 
      }
   }
}

And example output is this.

Hello, World!
You entered the following 4 command line arguments:
A
B
C
D

I don't know how to change the signature of the Main method. How can I change this code to get example output?


+ My output is this.

Hello, World!
You entered the following 0 command line arguments:

It's all.

2 Answers2

1

You don't. There are only two versions of Main: one which ignores the command-line arguments and one which receives them. You are using the latter. In order for the code to print A B C D, you need to invoke your program like this:

Hello3.exe A B C D

Alternately you can fake the command-line arguments with Visual Studio as described here.

Community
  • 1
  • 1
Amadan
  • 191,408
  • 23
  • 240
  • 301
1

The method signature has already been changed to support that Main method's body. The method states for each string passed in the string array of arguments, print the count, then each item passed in.

You can get that literal output by executing the application via command line and passing in A B C D.

See https://msdn.microsoft.com/en-us/library/aa288457(v=vs.71).aspx for a tutorial on passing command arguments to your application.

In your case it could be:

Hello3.exe A B C D

Kritner
  • 13,557
  • 10
  • 46
  • 72