C# Linq Contains Method


To check for an element in a string, use the Contains() method.

The following is our string array.

string[] arr = { "Java", "C++", "Python"};

Now, use Contains() method to find a specific string in the string array.

arr.AsQueryable().Contains(str);

Let us see the complete example.

Example

 Live Demo

using System;
using System.Linq;
using System.Collections.Generic;
class Demo {
   static void Main() {
      string[] arr = { "Java", "C++", "Python"};
      string str = "Python";
      bool res = arr.AsQueryable().Contains(str);
      Console.WriteLine("Array has Python? "+res);
   }
}

Output

Array has Python? True

Updated on: 23-Jun-2020

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements