Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.
6 out of 20 rated this helpful - Rate this topic

How to: Access Command-Line Arguments Using foreach (C# Programming Guide)

Another approach to iterating over the array is to use the foreach statement as shown in this example. The foreach statement can be used to iterate over an array, a .NET Framework collection class, or any class or struct that implements the IEnumerable interface.

Example

This example demonstrates how to print out the command line arguments using foreach.

// arguments: John Paul Mary

class CommandLine2
{
    static void Main(string[] args)
    {
        System.Console.WriteLine("Number of command line parameters = {0}", args.Length);

        foreach (string s in args)
        {
            System.Console.WriteLine(s);
        }
    }
}

Output

 
Number of command line parameters = 3
John
Paul
Mary

See Also

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft. All rights reserved.