Determine if the array contains the specified number. - CSharp System

CSharp examples for System:Array Search

Description

Determine if the array contains the specified number.

Demo Code

// Licensed under the Apache License, Version 2.0 (the "License");
using System.Collections.Generic;
using System;/*from   ww  w.j  av a2  s .c  o m*/

public class Main{
        /// <summary>
        /// Determine if the array contains the specified number.
        /// </summary>
        /// <param name="array">The array to search.</param>
        /// <param name="target">The number being searched for.</param>
        /// <returns>True, if the number was found.</returns>
        public static bool Contains(int[] array, int target)
        {
            for (int i = 0; i < array.Length; i++)
            {
                if (array[i] == target)
                {
                    return true;
                }
            }

            return false;
        }
}

Related Tutorials