Create a console application to display different messages depending onthe command line argument value. Use Select-case statements.(similar toswitch block)
1
Expert's answer
2011-05-23T11:18:57-0400
using System;
namespace CommandLineArguments { class Program { & static void Main(string[] args) & { // The first element of the array is the name of the program, // so we'll ignore it (it isn't a parameter) for (int i = 0; i < args.Length; i++) { // Looking for some special parameters switch (args[i]) { & case "-h": Console.WriteLine("The help parameter was detected!"); break; & case "a": Console.WriteLine("The parameter 'a' was detected!"); break; & case "b": Console.WriteLine("The parameter 'b' was detected!"); break; & case "c": Console.WriteLine("The parameter 'c' was detected!"); break; & case "SomeParameter": Console.WriteLine("'SomeParameter was detected!"); break;
Comments
Leave a comment