Advertisement
Obada8

Use Main method argument example

Jan 27th, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.76 KB | None | 0 0
  1. using System;
  2.  
  3. class Program
  4. {
  5.     static void Main(string[] args)
  6.     {
  7.         if (args == null)
  8.         {
  9.             Console.WriteLine("args is null");
  10.         }
  11.         else
  12.         {
  13.             bool boolContinue = (args.Length) == 1 ? true : false;
  14.  
  15.             for (int i = 0; i < args.Length && boolContinue; i++)
  16.             {
  17.                 string argument = args[i];
  18.                 Console.Write("args index ");
  19.                 Console.Write(i); // Write index
  20.                 Console.Write(" is [");
  21.                 Console.Write(argument); // Write string
  22.                 Console.WriteLine("]");
  23.             }
  24.  
  25.             if (!boolContinue)
  26.                 Console.Write("Invaild argument");
  27.         }
  28.         Console.ReadLine();
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement