Exercise 3-10 (Three command-line arguments)
Chapter_3 Exercise_3-9 StaticField | Show_Properties Exercise_3-11 |
Exercise 3-10 TCS, p. 86
Exercise 3-10. Write a program that prints three arguments taken from the command line. To do this, you’ll need to index into the command-line array of
strings, using the
static void Main(string[] args)
form for your entry point.
Arguments.cs
public class Arguments
{
public static void Main(string[] args)
{
System.Console.WriteLine("args[0] = " + args[0]);
System.Console.WriteLine("args[1] = " + args[1]);
System.Console.WriteLine("args[2] = " + args[2]);
}
}
/*
mcs Arguments.cs
mono Arguments.exe
Exception System.IndexOutOfRangeException: Arguments.Main (System.String[] args) [0x00000]
mono Arguments.exe Hello
args[0] = Hello
Exception System.IndexOutOfRangeException: Arguments.Main (System.String[] args) [0x00012]
mono Arguments.exe Hello, guys!
args[0] = Hello,
args[1] = guys!
Exception System.IndexOutOfRangeException: Arguments.Main (System.String[] args) [0x00024]
mono Arguments.exe How are you?
args[0] = How
args[1] = are
args[2] = you?
mono Arguments.exe How are you, friend?
args[0] = How
args[1] = are
args[2] = you,
*/
Chapter_3 Exercise_3-9 StaticField | BACK_TO_TOP | Show_Properties Exercise_3-11 |
Comments
Post a Comment