---
title: "why are use LINQ Where Clause in LINQ?"  
description: "why are use LINQ Where Clause in LINQ?"  
author: "Ethan Karla"  
published: 2021-09-24  
updated: 2021-09-24  
canonical: https://www.mindstick.com/forum/156759/why-are-use-linq-where-clause-in-linq  
category: "linq"  
tags: ["c#", "ado.net", "linq"]  
reading_time: 6 minutes  

---

# why are use LINQ Where Clause in LINQ?

How to use [LINQ](https://www.mindstick.com/articles/12007/language-integrated-query-linq-queries) [Where Clause](https://www.mindstick.com/interview/1909/when-do-you-use-where-clause-and-when-do-you-use-having-clause) [Filtering](https://www.mindstick.com/forum/33958/how-to-filtering-with-the-entity-framework-is-an-asp-dot-net-mvc-application) [Operator in SQL](https://www.mindstick.com/forum/160543/how-to-filter-records-using-like-operator-in-sql-server) [data](https://www.mindstick.com/articles/13050/salesforce-aiming-to-dominate-predictive-analytics-with-data-science) or normal data?

## Replies

### Reply by Ravi Vishwakarma

In LINQ where clauses are used for filtering the collection or SQL data. In another word where clauses help to filter the condition-based data for collection or SQL server.

## Syntax

```
datatype variable = from object in collections                   where condition,                   where condition                   select object;
```

```
datatype variable = collection.where( lambda variable => condition );
```

## Example

```
using System;using System.Collections.Generic;using System.Linq;
public class Program{ public static void Main() {  List<Student> students = new List<Student>()  {  new Student() { StudentId = 1, Name = 'Asu', Marks = 500 },  new Student() { StudentId = 2, Name = 'Shyam', Marks = 300 },  new Student() { StudentId = 3, Name = 'Shriyam', Marks = 400 },  new Student() { StudentId = 4, Name = 'Sunny', Marks = 550 },  new Student() { StudentId = 5, Name = 'Ram', Marks = 600 },  new Student() { StudentId = 6, Name = 'Krishna', Marks = 700 },  new Student() { StudentId = 7, Name = 'Anupam', Marks = 550 }  };
  // select projection using first sysntax
  var result1= from student in students      where student.Marks > 300 && student.Marks < 700     select student ;
  Console.WriteLine('Using First Syntax :\n');  result1.ToList().ForEach(item => Console.WriteLine('StudentName is {0}, ID is {1}, and Marks is {2}', item.Name, item.StudentId, item.Marks) );
  var result2 = from student in students       where student.Marks > 300       where student.Marks < 700       select new {Name =student.Name,ID = student.StudentId,Marks = student.Marks };
  Console.WriteLine('\nUsing Second Syntax :\n');  result2.ToList().ForEach(item => Console.WriteLine('StudentName is {0}, ID is {1}, and Marks is {2}', item.Name, item.ID, item.Marks) );
  var result3 = students.Where( student => student.StudentId < 5);
  Console.WriteLine('\nUsing where method Syntax :\n');  result3.ToList().ForEach(item => Console.WriteLine('StudentName is {0}, ID is {1}, and Marks is {2}', item.Name, item.StudentId, item.Marks) );
  Console.ReadLine(); }}
```

```
class Student{public int StudentId { get; set; }public string Name { get; set; }public int Marks { get; set; }}
```

## Output

```
Using First Syntax :
StudentName is Asu, ID is 1, and Marks is 500
StudentName is Shriyam, ID is 3, and Marks is 400
StudentName is Sunny, ID is 4, and Marks is 550
StudentName is Ram, ID is 5, and Marks is 600
StudentName is Anupam, ID is 7, and Marks is 550
Using Second Syntax :
StudentName is Asu, ID is 1, and Marks is 500
StudentName is Shriyam, ID is 3, and Marks is 400
StudentName is Sunny, ID is 4, and Marks is 550
StudentName is Ram, ID is 5, and Marks is 600
StudentName is Anupam, ID is 7, and Marks is 550
Using where method Syntax :
StudentName is Asu, ID is 1, and Marks is 500
StudentName is Shyam, ID is 2, and Marks is 300
StudentName is Shriyam, ID is 3, and Marks is 400
StudentName is Sunny, ID is 4, and Marks is 550
```

\

### Reply by Ravi Vishwakarma

In **LINQ where clauses** are used for filtering the collection or [SQL](https://www.mindstick.com/articles/13115/types-of-keys-in-sql-or-oracle-database) data. In another word where clauses help to filter the condition-based data for collection or SQL server.

## Syntax

```
datatype variable = from object in collections                    where condition,                    where condition                    select object;
```

```
datatype variable = collection.where( lambda variable => condition );
```

## \

## Example

```
using System;using System.Collections.Generic;using System.Linq;public class Program{ public static void Main() {  List<Student> students = new List<Student>()  {  new Student() { StudentId = 1, Name = 'Asu', Marks = 500 },  new Student() { StudentId = 2, Name = 'Shyam', Marks = 300 },  new Student() { StudentId = 3, Name = 'Shriyam', Marks = 400 },  new Student() { StudentId = 4, Name = 'Sunny', Marks = 550 },  new Student() { StudentId = 5, Name = 'Ram', Marks = 600 },  new Student() { StudentId = 6, Name = 'Krishna', Marks = 700 },  new Student() { StudentId = 7, Name = 'Anupam', Marks = 550 }  };
  // select projection using first sysntax  var result1= from student in students                where student.Marks > 300 && student.Marks < 700               select student ;  Console.WriteLine('Using First Syntax :\n');  result1.ToList().ForEach(item => Console.WriteLine('StudentName is {0}, ID is {1}, and Marks is {2}', item.Name, item.StudentId, item.Marks) );
  var result2 = from student in students                where student.Marks > 300                where student.Marks < 700                select new {Name =student.Name,ID = student.StudentId,Marks = student.Marks };
  Console.WriteLine('\nUsing Second Syntax :\n');  result2.ToList().ForEach(item => Console.WriteLine('StudentName is {0}, ID is {1}, and Marks is {2}', item.Name, item.ID, item.Marks) );
  var result3 = students.Where( student => student.StudentId < 5);  Console.WriteLine('\nUsing where method Syntax :\n');  result3.ToList().ForEach(item => Console.WriteLine('StudentName is {0}, ID is {1}, and Marks is {2}', item.Name, item.StudentId, item.Marks) );
  Console.ReadLine(); }}
```

```
class Student{public int StudentId { get; set; }public string Name { get; set; }public int Marks { get; set; }}
```

Output

```
Using First Syntax :
StudentName is Asu, ID is 1, and Marks is 500
StudentName is Shriyam, ID is 3, and Marks is 400
StudentName is Sunny, ID is 4, and Marks is 550
StudentName is Ram, ID is 5, and Marks is 600
StudentName is Anupam, ID is 7, and Marks is 550
Using Second Syntax :
StudentName is Asu, ID is 1, and Marks is 500
StudentName is Shriyam, ID is 3, and Marks is 400
StudentName is Sunny, ID is 4, and Marks is 550
StudentName is Ram, ID is 5, and Marks is 600
StudentName is Anupam, ID is 7, and Marks is 550
Using where method Syntax :
StudentName is Asu, ID is 1, and Marks is 500
StudentName is Shyam, ID is 2, and Marks is 300
StudentName is Shriyam, ID is 3, and Marks is 400
StudentName is Sunny, ID is 4, and Marks is 550
```

\


---

Original Source: https://www.mindstick.com/forum/156759/why-are-use-linq-where-clause-in-linq

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
