Advertisement
Shaun_B

Example of how to send parameters to String [ ] args

Oct 2nd, 2013
454
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.50 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace TestConsoleApplication
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             /// Sets the title bar on our console
  14.             Console.Title = "Using Command Line... Like a DOS!";
  15.             /// Set up a integer in local scope, initialising it to zero
  16.             int counter = 0;
  17.             /// Clears the console, like cls (CLear Screen)
  18.             Console.Clear();
  19.             /// Checks if there's any arguments first
  20.             if (args.Length > 0)
  21.             {
  22.                 /// If args has been added, then we'll display each one
  23.                 foreach (var arg in args)
  24.                 {
  25.                     Console.Write(arg);
  26.                     Console.Write(" ");
  27.                     counter++;
  28.  
  29.                 }
  30.                 /// Escape string for newline
  31.                 Console.Write("\n");
  32.                 Console.Write("\nNumber of arguments sent: " + counter);
  33.                 Console.Write("\n");
  34.             }
  35.             /// Here's a generic message, like "Hello World" or whatever:
  36.             /// Note: WriteLine adds a carriage return after writing the text
  37.             Console.WriteLine("I can do Computers me!");
  38.             Console.Write("Press the Any key to exit...");
  39.             /// Wait for key-press
  40.             Console.ReadKey(true);
  41.             /* FIN - Exit application */
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement