其实一行代码就可以了,不用写那么多循环,先看看老外写的代码

复制代码
using System;

class Program
{
staticvoid Main()
   {
string[] array = { "cat", "dot", "perls" };

// Use Array.Exists in different ways.
bool a = Array.Exists(array, element => element =="perls");
bool b = Array.Exists(array, element => element =="python");
bool c = Array.Exists(array, element => element.StartsWith("d"));
bool d = Array.Exists(array, element => element.StartsWith("x"));

// Output.
   Console.WriteLine(a);
   Console.WriteLine(b);
   Console.WriteLine(c);
   Console.WriteLine(d);
   }
复制代码


string[] SetSelectIds = string[] { "aa", "bb", "cc" };

string id = string "bb";

if (Array.Exists(SetSelectIds, element => element.Equals(id)))


Array.IndexOf(SetSelectIds, id) >= 0;