How to create Search option with the help of Linq in C#
Here we wil use linq query where clause and contain for find the words.
Progarm
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace test
{
class Program
{
static void Main(string[] args)
{
string[] name = {"Adam", "Loren","Jhone"};
Console.WriteLine("Enter the letter:-");
string rr = Console.ReadLine();
var s = from r in name where r.Contains(rr) select r;
foreach (var i in s)
{
Console.WriteLine(i.ToString());
}
Console.ReadLine();
}
}
}
Input:- Enter the Letter:- e
Output:- Loren
Jhone
Next
Input:- Enter the Letter:- A
Output:- Adam
Here we wil use linq query where clause and contain for find the words.
Progarm
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace test
{
class Program
{
static void Main(string[] args)
{
string[] name = {"Adam", "Loren","Jhone"};
Console.WriteLine("Enter the letter:-");
string rr = Console.ReadLine();
var s = from r in name where r.Contains(rr) select r;
foreach (var i in s)
{
Console.WriteLine(i.ToString());
}
Console.ReadLine();
}
}
}
Input:- Enter the Letter:- e
Output:- Loren
Jhone
Next
Input:- Enter the Letter:- A
Output:- Adam