String[] args in C#

String[] args is a parameter of the Main method that represents the command-line arguments passed to the application when it is executed1. For example, if you run your application like this:

MyApp.exe arg1 arg2 arg3

The args array will contain three strings: "arg1", "arg2", and "arg3".

You can use the args array to access the command-line arguments and perform different actions based on them. For example, you can write a program that copies a file from one location to another by passing the source and destination paths as arguments1.

Here is a simple example of how to use String[] args in C#:

  1. public class Program {  
  2.     static void Main(string[] args)
  3.     {
  4.         Console.WriteLine("Number of arguments: " + args.Length);
  5.         foreach (string arg in args)
  6.         {
  7.            Console.WriteLine("Argument: " + arg);
  8.          }
  9.      }
  10. }  


Comments

Popular posts from this blog

C# | Association, Aggregation and Composition

Throw vs Throw ex in C#

C# Extension Method