Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
C# Program to search for a string in an array of strings
Use Linq Contains() method to search for as specific string in an array of strings.
string[] arr = { "Bag", "Pen", "Pencil"};
Now, add the string in a string variable i.e. the string you want to search.
string str = "Pen";
Use the Contains() method to search the above string.
arr.AsQueryable().Contains(str);
Let us see the entire example.
Example
using System;
using System.Linq;
using System.Collections.Generic;
class Demo {
static void Main() {
string[] arr = { "Bag", "Pen", "Pencil"};
string str = "Pen";
bool res = arr.AsQueryable().Contains(str);
Console.WriteLine("String Pen is in the array? "+res);
}
}
Output
String Pen is in the array? True
Advertisements
