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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
SenthilkumarPosted Apr 7, 2012, 3:01 AM
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.
VulpesPosted Apr 6, 2012, 5:05 AM
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.
MuthuMari MPosted Apr 6, 2012, 4:58 AM
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"
Kunal NaikPosted Apr 6, 2012, 1:15 AM
Please refer below link,
Click Here
Jignesh TrivediPosted Apr 6, 2012, 1:11 AM
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.