Check if an int array contains an element in CSharp
Description
The following code shows how to check if an int array contains an element.
Example
using System;/*w w w . ja va 2 s .c om*/
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
public class MainClass{
public static void Main(){
int[] numbers = { 2, 6, 1, 56, 102 };
Console.WriteLine("Is there the number 102?");
Console.Write(numbers.Contains(102) ? "Yes, there is" : "No, there isn't");
}
}
The code above generates the following result.