Test your technical skills online, appear in Virtual Interview and be ready for job!
Twitter Twitter LinkedIn YouTube Google
Be Interview ready ! | Search
Make friends on DotNetFunda.com and expand your network!

Win Prizes

Like us on Facebook
Top Articles Author
Fri, 18-Apr-2014 Authors
All Time Authors
Bharathi Cherukuri

Latest members | More ...

(Statistics delayed by 5 minutes)

How to implement IN clause in LINQ/LAMBDA Query expression?Explain with an example.

 Posted by Niladri.Biswas on 7/11/2012 | Category: C# Interview questions | Views: 1087 | Points: 40

This can be done using the "Contains" extension method. Example follows.

Suppose we have a person class as under

public class Person

public string PersonName { get; set; }
public string JobTitle { get; set; }

public override string ToString()
return "Person Name: " + PersonName + " JobTitle:" + JobTitle;

Then populate the Person collection as under

private static List<Person> PreparePersonCollection()

List<Person> lstPersonCollection = new List<Person>();
lstPersonCollection.Add(new Person { PersonName = "Amitav Sen", JobTitle = "Design Engineer" });
lstPersonCollection.Add(new Person { PersonName = "Bhavini Dey", JobTitle = "Software Engineer" });
lstPersonCollection.Add(new Person { PersonName = "Debasis Basu", JobTitle = "Software Engineer" });
lstPersonCollection.Add(new Person { PersonName = "Kartik Moin", JobTitle = "Lead Engineer" });
lstPersonCollection.Add(new Person { PersonName = "Shahjahan Khan", JobTitle = "Technical Lead" });

return lstPersonCollection;

Suppose we want to get the list of Person who has job Title as "Design Engineer", "Software Engineer".

The complete query will be as under

List<Person> source = PreparePersonCollection();

string[] strJobTitleToInclude = new string[] { "Design Engineer", "Software Engineer" };

.ForEach(i => Console.WriteLine(i.ToString()));


Person Name: Amitav Sen JobTitle:Design Engineer

Person Name: Bhavini Dey JobTitle:Software Engineer
Person Name: Debasis Basu JobTitle:Software Engineer

Asked In: Many Interviews | Alert Moderator 

Found interesting? Add this to:

Comments or Responses

Login to post response.

Comments / Responses
Select text & click toolbar to format. Formatting appears in viewmode only. HTML Tags are not allowed.
Bold Italic Underline Paragraph Title Code  Link 
 Wait ... Processing ..... please wait.