2 Replies - 283 Views - Last Post: 28 December 2012 - 09:53 PM Rate Topic: -----

#1 psubill  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 18-September 09

question on basic code

Posted 28 December 2012 - 07:33 PM

I found this example on a site, loaded in VS and it just gives a blank black screen but sample says it has output. I was looking for something to explain what args is. Can someone explain what args is.
using System;

class Program
{
    static void Main(string[] args)
    {
	// The program control flow begins here.
	// ... Use a foreach loop.
	// ... Then use an equivalent for loop.
	foreach (string value in args)
	{
	    Console.WriteLine("foreach: {0}", value);
	}
	for (int i = 0; i < args.Length; i++)
	{
	    string value = args[i];
	    Console.WriteLine("for: {0}", value);
	}
	Console.ReadLine();
    }
}



Output is supposed to be:

foreach: Arg1
foreach: Arg2
foreach: Arg3
for: Arg1
for: Arg2
for: Arg3

Is This A Good Question/Topic? 0
  • +

Replies To: question on basic code

#2 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3549
  • View blog
  • Posts: 10,993
  • Joined: 05-May 12

Re: question on basic code

Posted 28 December 2012 - 09:45 PM

args are the command line parameters. So if you ran your executable in a CMD window and did something like "program.exe Luke I Am Your Father", the output would be:
foreach: Luke
foreach: I
foreach: Am
foreach: Your
foreach: Father
for: Luke
for: I
for: Am
for: Your
for: Father



If you don't want to run you program on the command line, you will have to run your program with command line parameters by bring up your project properties page and entering values for command line arguments.
Was This Post Helpful? 4
  • +
  • -

#3 psubill  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 18-September 09

Re: question on basic code

Posted 28 December 2012 - 09:53 PM

Okay I see what your saying , Thanks

This post has been edited by psubill: 28 December 2012 - 09:54 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1