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#:
- public class Program {
- static void Main(string[] args)
- {
- Console.WriteLine("Number of arguments: " + args.Length);
- foreach (string arg in args)
- {
- Console.WriteLine("Argument: " + arg);
- }
- }
- }
Comments
Post a Comment