check if element is in array c# code example
Example 1: how to check if a value is inside an array c#
string[] printer = {"jupiter", "neptune", "pangea", "mercury", "sonic"};
if(printer.Contains("jupiter"))
{
Process.Start("BLAH BLAH CODE TO ADD PRINTER VIA WINDOWS EXEC"");
}
Example 2: c# check if array contains value
public static bool Contains(Array a, object val)
{
return Array.IndexOf(a, val) != -1;
}
Example 3: how to check if an integer is in array c#
using System.Linq;
string[] printer = {"jupiter", "neptune", "pangea", "mercury", "sonic"};
if(printer.Contains("jupiter"))
{
Process.Start("BLAH BLAH CODE TO ADD PRINTER VIA WINDOWS EXEC"");
}