C# Linq Contains Method

CsharpProgrammingServer Side Programming

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
raja
Published on 14-Sep-2018 16:35:43
Advertisements