If array contains an value - CSharp System

CSharp examples for System:Array Search

Description

If array contains an value

Demo Code


using Microsoft.Xna.Framework.Input;
using System;/* w  w  w .j  a  v  a  2 s  . c o m*/

public class Main{
        public static bool contains<T>( this T[] source, T value )
      {
         for( var i = 0; i < source.Length; i++ )
         {
            if( source[i].Equals( value ) )
               return true;
         }
         return false;
      }
        public static bool contains( this Keys[] source, Keys value )
      {
         for( var i = 0; i < source.Length; i++ )
         {
            if( source[i] == value )
               return true;
         }
         return false;
      }
        public static bool contains( this string[] source, string value )
      {
         for( var i = 0; i < source.Length; i++ )
         {
            if( source[i] == value )
               return true;
         }
         return false;
      }
        public static bool contains( this int[] source, int value )
      {
         for( var i = 0; i < source.Length; i++ )
         {
            if( source[i] == value )
               return true;
         }
         return false;
      }
}

Related Tutorials