Q:

# C# program to check the salary of all employees is less than 10000 using Linq

C# program to check the salary of all employees is less than 10000 using Linq

### All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

The source code to check the salary of all employees is less than 10000 using Linq, which is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.

``````//C# program to check the salary of all employees
//is less than 10000 using Linq.

using System;
using System.Linq;
using System.Collections.Generic;

public class Employee
{
int ID;
string Name;
int Salary;
string Department;

static void Main(string[] args)
{
bool isLessthan = false;

List<Employee> employees = new List<Employee>()
{
new Employee {ID=101,   Name="Amit  "    , Salary=4000,Department="ABC"},
new Employee {ID=102,   Name="Amit  "    , Salary=3000,Department="XYZ"},
new Employee {ID=103,   Name="Salman"    , Salary=3000,Department="ABC"},
new Employee {ID=104,   Name="Ram   "    , Salary=2000,Department="XYZ"},
new Employee {ID=105,   Name="Shyam "    , Salary=7000,Department="ABC"},
new Employee {ID=106,   Name="Kishor"    , Salary=5000,Department="XYZ"},
};

isLessthan = employees.All(emp => emp.Salary < 10000);

Console.WriteLine("The salary of all employees is less than 10000? " + isLessthan);
}
}``````

Output:

```The salary of all employees is less than 10000? True
Press any key to continue . . .
```

Explanation:

In the above program, we created the Employee class that contains the IDNameSalaryDepartment, and Main() method. In the Main() method, we created a list of employees.

```isLessthan = employees.All(emp => emp.Salary < 10000);
```

In the above statement, we checked the salary of all employees is less than 10000. If the salary of all employees is less than 10000 then the All() method will return true otherwise it will return false.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)