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

Here, we are going to learn how to check the salary of all employees is less than 10000 using Linq in C#?
Submitted by Nidhi, on August 31, 2020

Here we will create an Employee class and check the salary of all employees is less than 10000 using Linq All() method.

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 ID, Name, Salary, Department, 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.

C# LINQ Programs »


ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT


Top MCQs

Comments and Discussions!




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.