An if
statement selects a statement for execution based on the value of a boolean expression. An if
statement may optionally include an else
clause that executes if the boolean expression is false.
The example
using System; class Test { static void Main(string[] args) { if (args.Length == 0) Console.WriteLine("No arguments were provided"); else Console.WriteLine("Arguments were provided"); } }
shows a program that uses an if statement to write out two different messages depending on whether command-line arguments were provided or not.