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 ID, Name, Salary, Department, and Main() method. In the Main() method, we created a list of employees.
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.
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.
Output:
Explanation:
In the above program, we created the Employee class that contains the ID, Name, Salary, Department, and Main() method. In the Main() method, we created a list of employees.
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