3 Replies - 1519 Views - Last Post: 19 January 2010 - 03:35 PM Rate Topic: -----

#1 ghqwerty  Icon User is online

  • if($spareTime > 0){ $this->writeCode(); }
  • member icon

Reputation: 43
  • View blog
  • Posts: 891
  • Joined: 08-August 08

command line arguments

Posted 19 January 2010 - 03:11 PM

im trying to go through the msdn tutorials for c# and on one of the first ones i saw this however it just says that there are 0 commandline parameters.

could someone please tell me how you add a command line parameter?

p.s. i added in the Console.ReadLine();
// cmdline1.cs
// arguments: A B C
using System;

public class CommandLine
{
	public static void Main(string[] args)
	{
		// The Length property is used to obtain the length of the array. 
		// Notice that Length is a read-only property:
		Console.WriteLine("Number of command line parameters = {0}",
		   args.Length);
		for (int i = 0; i < args.Length; i++)
		{
			Console.WriteLine("Arg[{0}] = [{1}]", i, args[i]);
		}
		Console.ReadLine();
	}
}


Is This A Good Question/Topic? 0
  • +

Replies To: command line arguments

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6021
  • View blog
  • Posts: 23,395
  • Joined: 23-August 08

Re: command line arguments

Posted 19 January 2010 - 03:14 PM

Do you mean within the IDE? If so, under Project Properties->Debug->Start Options there's a Command line arguments box.
Was This Post Helpful? 0
  • +
  • -

#3 ghqwerty  Icon User is online

  • if($spareTime > 0){ $this->writeCode(); }
  • member icon

Reputation: 43
  • View blog
  • Posts: 891
  • Joined: 08-August 08

Re: command line arguments

Posted 19 January 2010 - 03:18 PM

thanks for the super speedy response there. got it sorted.

just for my knowledge when would you actually need to use this ?

and how would you call this from say within the script?
Was This Post Helpful? 0
  • +
  • -

#4 MentalFloss  Icon User is offline

  • "ADDICTED"[2:5]
  • member icon

Reputation: 526
  • View blog
  • Posts: 1,397
  • Joined: 02-September 09

Re: command line arguments

Posted 19 January 2010 - 03:35 PM

Quote

just for my knowledge when would you actually need to use this ?


You use it when your program expects command line parameters and you are running through debug mode. So this allows you to insert the parameters the application will use.

Quote

and how would you call this from say within the script?


When you run the application from command line, you pass in parameters by putting extra details on that invoke line. Example:

ping -t 127.0.0.1



Ping is the application. -t is a parameter as well as 127.0.0.1. (It can be argued that the application name "Ping" is a parameter too, but I won't get into that)

You may also set the startup parameters in a shortcut. This will have the same effect as directly expressing them in command line.

Hope this helps.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1