C# & VB.NET School Support

Moderators: None (Apply to moderate this forum)
Number of threads: 135
Number of posts: 228

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
What comand line code on lesson 3 excersice 5 suppose to do? Posted by DGR7 on 23 Sept 2004 at 7:52 AM
Hi

I am new to thie C# world, but I have a question regarding the following exercise of the school (Lesson 3) Excersise 5 (Write a program that prints all the command line arguments).

The code reads as follows:

using System;

namespace CSharpSchool
{
// program that prints all the command line arguments
class CommandLineArgs
{
static void Main(string [] args)
{
for(int i=0; i<args.Length; i++)
{
Console.WriteLine
("The {0}th command line argument: {1}",
i, args[i]);
}
}
}
}

QUESTION:

What am I suppose to see on the command screen?
What do you mean by comand line argument? I cannot see at any point the display of "The {0}th command line argument: {1}". Instead I only can see the string "Press any key to continue".

Thanks !!
Report
Re: What comand line code on lesson 3 excersice 5 suppose to do? Posted by Baldusarius on 26 Sept 2004 at 9:19 PM
: Hi
:
: I am new to thie C# world, but I have a question regarding the following exercise of the school (Lesson 3) Excersise 5 (Write a program that prints all the command line arguments).
:
: The code reads as follows:
:
: using System;
:
: namespace CSharpSchool
: {
: // program that prints all the command line arguments
: class CommandLineArgs
: {
: static void Main(string [] args)
: {
: for(int i=0; i<args.Length; i++)
: {
: Console.WriteLine
: ("The {0}th command line argument: {1}",
: i, args[i]);
: }
: }
: }
: }
:
: QUESTION:
:
: What am I suppose to see on the command screen?
: What do you mean by comand line argument? I cannot see at any point the display of "The {0}th command line argument: {1}". Instead I only can see the string "Press any key to continue".
:
: Thanks !!
:

It will print out the arguments supplied on the command line. For example:
appName.exe HeresAnArg Arg2
will output
The 0th command line argument: HeresAnArg
The 1th command line argument: Arg2
If no arguments are specified on the command line, the for loop will never execute and no ouput will be produced.

As an aside, you can see from the sample output that the string supplied to Console.WriteLine doesn't produce grammatically correct output (1th) and the second argument should be i+1 instead of i.

Report
Re: What comand line code on lesson 3 excersice 5 suppose to do? Posted by frazrasheed on 3 Oct 2004 at 9:39 AM
Hi,

To use this program, you need to run the program on command prompt. To run the program, just compile it and run the generated .exe file with some arguments ahead of it. For example, if you have named the program myProgram and compiled it to the myProgram.exe file, then if I write on command prompt:

C:\>myProgram abc xyz

Then it will print 0th argument as 'abc' and '1th' argument as 'xyz'. We purposefully and intentionally did not change the first item's position from 0 to 1 here as we liked to make it very clear that when talking about arguments (or in general arrays in C#) then the first item always has the index value zero (0), second item has one (1) and so on. But if you like the other way, you can print simply i+1th value to print 1th value with first item and 2th value with second item

Regards,
Faraz

: Hi
:
: I am new to thie C# world, but I have a question regarding the following exercise of the school (Lesson 3) Excersise 5 (Write a program that prints all the command line arguments).
:
: The code reads as follows:
:
: using System;
:
: namespace CSharpSchool
: {
: // program that prints all the command line arguments
: class CommandLineArgs
: {
: static void Main(string [] args)
: {
: for(int i=0; i<args.Length; i++)
: {
: Console.WriteLine
: ("The {0}th command line argument: {1}",
: i, args[i]);
: }
: }
: }
: }
:
: QUESTION:
:
: What am I suppose to see on the command screen?
: What do you mean by comand line argument? I cannot see at any point the display of "The {0}th command line argument: {1}". Instead I only can see the string "Press any key to continue".
:
: Thanks !!
:




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.