BlackVikingPro BlackVikingPro - 1 year ago 98
C# Question

Searching Arrays with Strings from other Arrays C#

I have this thing for checking if the client entered some help command in the arguments while triggering the console application I've built in C#. Below is my current code to complete this task:

string[] help = { "-h", "--help", "/?", "help", "-help", "*help*" };
if (args.Contains(help[*])
Usage(); // prints out application usage
Environment.Exit(1); // exits console application only

I originally used the following, which worked, but I wanted to clean the code up a little bit:

if (args.Contains("-h") || args.Contains("--help") || args.Contains("/?") ...)

How would I perform the task I'm trying to perform in the cleanest coded way possible?

Thanks in advance :)

Answer Source

How about args.Any(arg => help.Contains(arg))?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download