 Open in App
Not now

# C# Program to Check the Salary of all Employees is Less than 10000 using LINQ

• Last Updated : 06 Dec, 2021

Given the data of employees, now our task is to check if all the employee salaries are less than 10000. So we use the All() method of LINQ. This method is used to check if all the elements in the source sequence satisfy the given condition. It will return true if all the elements present in the given sequence pass the test. Otherwise, it will return false. So the solve the given problem we use the following LINQ query:

result = Geeks.All(geek => geek.Emp_Salary < 10000);

Here, result is a boolean type variable that is used to store the final result, Geeks is the sequence and All() method is used to find the list of employees whose salary is less than 10000.

Example:

```Input: {id = 301, Name = Mohit, Salary = 10000}
{id = 302, Name = Priya, Salary = 20000}
{id = 303, Name = Sohan, Salary = 40000}
{id = 304, Name = Rohit, Salary = 10000}
Output: False

Input: {id = 401, Name = Rohan, Salary = 1000}
{id = 404, Name = Mohan, Salary = 4000}
Output: True```

Example 1:

## C#

 `// C# program to determine the salary of all employees ` `// is less than 10000  ` `using` `System; ` `using` `System.Linq; ` `using` `System.Collections.Generic; ` ` `  `class` `Geek{ ` `     `  `#pragma warning disable 169, 414 ` `int` `emp_id; ` `string` `Emp_Name; ` `int` `Emp_Salary; ` `string` `Emp_Department; ` ` `  `static` `void` `Main(``string``[] args) ` `{ ` `     `  `    ``// List of employee details  ` `    ``List Geeks = ``new` `List() ` `    ``{ ` `        ``new` `Geek{emp_id = 401, Emp_Name = ``"Rajat"``, Emp_Salary = 50000}, ` `        ``new` `Geek{emp_id = 402, Emp_Name = ``"Ram"``, Emp_Salary = 65000}, ` `        ``new` `Geek{emp_id = 403, Emp_Name = ``"Krishna"``, Emp_Salary = 45000}, ` `        ``new` `Geek{emp_id = 404, Emp_Name = ``"Sonial"``, Emp_Salary = 20000}, ` `        ``new` `Geek{emp_id = 405, Emp_Name = ``"Mickey"``, Emp_Salary = 70000}, ` `        ``new` `Geek{emp_id = 406, Emp_Name = ``"Kunti"``, Emp_Salary = 50000}, ` `    ``}; ` `    ``bool` `result; ` `     `  `    ``// Checking the salary of all employees ` `    ``// is less than 10000  ` `    ``result = Geeks.All(geek => geek.Emp_Salary < 10000); ` `     `  `    ``// Display result ` `    ``if` `(result) ` `    ``{ ` `        ``Console.Write(``"All the salaries are less than 10000"``); ` `    ``} ` `    ``else` `    ``{ ` `        ``Console.Write(``"All the salaries are not less than 10000"``); ` `    ``} ` `} ` `}`

Output

`All the salaries are not less than 10000`

Example 2:

## C#

 `// C# program to determine the salary of all employees ` `// is less than 10000  ` `using` `System; ` `using` `System.Linq; ` `using` `System.Collections.Generic; ` ` `  `class` `Geek{ ` `     `  `#pragma warning disable 169, 414 ` `int` `emp_id; ` `string` `Emp_Name; ` `int` `Emp_Salary; ` `string` `Emp_Department; ` ` `  `static` `void` `Main(``string``[] args) ` `{ ` `     `  `    ``// List of employee details  ` `    ``List Geeks = ``new` `List() ` `    ``{ ` `        ``new` `Geek{emp_id = 501, Emp_Name = ``"Rohan"``, Emp_Salary = 3000}, ` `        ``new` `Geek{emp_id = 502, Emp_Name = ``"Mohan"``, Emp_Salary = 3000}, ` `        ``new` `Geek{emp_id = 503, Emp_Name = ``"Sham"``, Emp_Salary = 4000}, ` `        ``new` `Geek{emp_id = 504, Emp_Name = ``"Sonial"``, Emp_Salary = 1000}, ` `    ``}; ` `    ``bool` `result; ` `     `  `    ``// Checking the salary of all employees ` `    ``// is less than 10000  ` `    ``result = Geeks.All(geek => geek.Emp_Salary < 10000); ` `     `  `    ``// Display the result ` `    ``Console.WriteLine(``"Is the salary of the Geek's employees is < 10000: "` `+ result); ` `} ` `} `

Output

`Is the salary of the Geek's employees is < 10000: True`

My Personal Notes arrow_drop_up
Related Articles