C#判断某元素是否存在数组中

 

 

string数组

 

  1. string[] s1 = new string[3] { "John", "Paul", "Mary" };
  2.  
    if (s1.Contains("John"))
  3.  
    Response.Write("fadfadfa");
  4.  

int数组

 

    1. int[] ia = {1,2,3};
    2.  
      int id = Array.IndexOf(ia,value);
    3.  
       
    4.  
      if(id==-1)
    5.  
      不存在
    6.  
      else
    7.  
      存在
    8.  

posted @ 2019-06-24 10:48  饮木  阅读(2712)  评论(0编辑  收藏  举报