C#中怎么判断一个数组中是否存在某个数组值

(1) 第一种方法:

int[] ia = {1,2,3};
int id = Array.IndexOf(ia,1); // 这里的1就是你要查找的值
if(id==-1)
// 不存在
else
// 存在

(2) 第二种方法:

string[] strArr = {"a","b","c","d","e"};
bool exists = ((IList)strArr).Contains("a");
if(exists)
// 存在
else
// 不存在

注意: 用IList需要using System.Collections;

JS:IE8中的数组没有indexOf这个方法,ie10有。

js:字符串转换成数组:str.split(",");括号内按照字符串中的符号来写

数组转换成字符串:Array.join("#"),#代表分隔的符号

原文地址:https://www.cnblogs.com/superelement/p/7691229.html