转自:http://blog.youkuaiyun.com/happymagic/article/details/6973831
法一:
string[] s1 = new string[3] { "John", "Paul", "Mary" };
if (s1.Contains("John"))
Response.Write("fadfadfa");
法二:
int[] ia = {1,2,3};
int id = Array.IndexOf(ia,value);
if(id==-1)
不存在
else
存在

本文介绍两种在C#中判断数组或集合中是否存在特定元素的方法。第一种方法使用了string数组与Contains方法;第二种方法则利用了Array.IndexOf方法针对int数组进行查找。这些方法有助于快速定位元素是否存在。
1335

被折叠的 条评论
为什么被折叠?



