(1) 第一種方法:
1 int[] ia = {11,22,33}; 2 int id = Array.IndexOf(ia,11); // 這里的1就是你要查找的值 3 if(id==-1) 4 // 不存在 5 else 6 // 存在
(2) 第二種方法:
1 string[] strArr = {"a","b","c","d","e"}; 2 bool exists = ((IList)strArr).Contains("a"); 3 if(exists) 4 // 存在 5 else 6 // 不存在
注意: 用IList需要using System.Collections;
數組中不能直接indexOf這個方法,需要 Array.IndexOf(x,x);這樣來使用
字符串轉換成數組:str.split(",");括號內按照字符串中的符號來寫
數組轉換成字符串:Array.join("#"),#代表分隔的符號