Hi guys,
Can anyone tell me what is the use of GetCommandLineArgs() method in C#.
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Jignesh TrivediRank #16 · 50.3K reputationPosted Apr 5, 2012, 9:11 PM EDT
The GetCommandLineArgs() method is used to access the command line arguments.
it Returns a string array containing the command-line arguments for the current process.
this method is from System.Environment class
Example
String[] arguments = Environment.GetCommandLineArgs();
Console.WriteLine("GetCommandLineArgs: {0}", String.Join(", ", arguments));
hope this help.
Kunal Naik163 reputationPosted Apr 5, 2012, 9:15 PM EDT
Please refer below link,
Click Here
MuthuMari MRank #5,738 · 288 reputationPosted Apr 6, 2012, 12:58 AM EDT
With GetCommandLineArgs() method, the command line arguments can be accessed.
The value returned is an array of strings. It is a method of the System.Environment class. See the code example below:
C# Example
public static int Main(string[] args)
{
string[] strArgs = System.Environment.GetCommandLineArgs();
Console.WriteLine("Arguments {0}", strArgs[0]);
}
Thanks.
If this post is useful then mark it as "Accepted Answer"
VulpesRank #55 · 29.2K reputationPosted Apr 6, 2012, 1:05 AM EDT
The former returns the file name of the executing program as the first element of the array. The latter does not.
GetCommandLineArgs() is used when you want to retrieve the program's command line arguments from somewhere other than the Main() method or to retrieve the program's file name. There are, however, other ways to do the second of these operations.
SenthilkumarRank #387 · 6.5K reputationPosted Apr 6, 2012, 11:01 PM EDT
GetCommandLineArgs method returns a string array containing the command-line arguments for the current process. Although you can receive command line arguments in the Main entry point in the C# language, the GetCommandLineArgs method can be used anywhere.