BlackVikingPro BlackVikingPro - 3 months ago 50
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 :)


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