HomeCSharpUsing SQL “IN” Clause in LINQ Query

Using SQL “IN” Clause in LINQ Query

When using the SQL Query, we could use the IN keyword to find the item something like this

SELECT * FROM MOVIES WHERE Movie_Name IN ('Thalaivaa', 'Jilla', 'Arrambam')

How to use achieve the similar results when using LINQ?

Using SQL “IN” Clause in LINQ Query

You could use the contains extension method to achieve the similar result as shown in the below code snippet.

string[] MovieNames = new string[] { "Thuppaki", "Thalaivaa", "Jilla", "Arrambam" };

string[] CurrentName = new string[] { "Thalaivaa", "Jilla", "Arrambam" };

var selectedName = (from u in MovieNames

where CurrentName.Contains(u)

select u);

foreach (var item in selectedName)

Console.WriteLine(item);

Console.ReadLine();

Using SQL "IN" Clause in LINQ Query

Leave a Reply

You May Also Like

This C# program calculates and displays an upper triangular matrix based on user input. Problem Statement: The program takes the...
This C# program serves as a demonstration of bitwise operators, which are fundamental operators used for manipulating individual bits in...
This C# program is designed to interchange or swap the columns of a matrix. A matrix is a two-dimensional array...