總結N種方法,待補充完善
一、 Array.IndexOf
int id = Array.IndexOf(string[],"要查找的值");
if(id!=-1)
或寫成
if(Array.IndexOf(string[],"要查找的值") >= 0)
二、IList
((IList)string[]).Contains"要查找的值")
三、Array.Exists
if (Array.Exists(SetSelectIds, element => element.Equals(id)))
四、待補充
參考:
C#中怎么判斷一個數組中是否存在某個數組值 C# 一個字符串是否在另外一個字符串數組里 Array.Exists 的用法 Array.IndexOf 用法