C# Program to Check a Specified Employee Exists in the List of Employees Using LINQ

Using this tutorial you will successfully complete the task of C# Program to Check a Specified Employee Exists in the List of Employees Using LINQ Let’s go

C# Program to Check a Specified Employee Exists in the List of Employees Using LINQ

C# Program to Check a Specified Employee Exists in the List of Employees Using LINQ

//C# program to check specified employees exist 
//in the list of employees 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 isExist = 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"},
        };

        
        Employee Emp1 = new Employee() {ID=107,   Name="Amit  "    , Salary=4000,Department="ABC"};

        isExist = employees.AsEnumerable().Contains(Emp1);

        if(isExist==true)
            Console.WriteLine("Emp1 exists in the employees list");
        else
            Console.WriteLine("Emp1 does not exist in the employee's list");
    }
}
Emp1 does not exist in the employee's list
Press any key to continue . . .

Final Words

We hope you find the C# Program to Check a Specified Employee Exists in the List of Employees Using LINQ. What to do if there are any issues with this article? Then ask through the comment section.

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Deekshi. Here, I post about programming to help developers.

Share on:

Leave a Comment