Check if the array contains a value - CSharp System

CSharp examples for System:Array Search

Description

Check if the array contains a value

Demo Code


using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;//  w  ww.j av a2 s.  c o  m

public class Main{
        /// <summary>
    /// Check if the array contains a value
    /// </summary>
    /// <param name="arr">Haystack</param>
    /// <param name="obj">Needle</param>
    /// <returns></returns>
    public static bool Has(dynamic arr, dynamic obj)
    {
      foreach(dynamic curr in arr)
      {
        if (Compare.Equal(curr, obj))
          return true;
      }

      return false;
    }
}

Related Tutorials