Use Contains to check the existance of an element : Contains « LINQ « C# / C Sharp






Use Contains to check the existance of an element

 
using System;
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");
   }
}

 








Related examples in the same category

1.Contains with string value
2.Contains with string value and IEqualityComparer
3.Contains with predicate returned false
4.Contains with IEqualityComparer
5.A query to extract strings containing the letter "a", sorted by length and converted to uppercase