C# program to join Employee and Department class and employee’s salary must be greater than 3000 using Linq

Hello, C# program to join Employee and Department class and employee’s salary must be greater than 3000 using Linq We are going to know the vibrancy of. There are many interesting facts in this article. Let’s move on to the articles

C# program to join Employee and Department class and employee's salary must be greater than 3000 using Linq

C# program to join Employee and Department class and employee’s salary must be greater than 3000 using Linq

//C# program to join Employee and Department class 
//and employees salary must be greater than 3000 using Linq.

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

public class Employee
{
    public int ID;
    public int Salary;
    public int DEPT_ID;
    public string Name;
}

public class Department
{
    public int DEPT_ID;
    public string DEPT_Name;
}

public class JoinDemo
{
    static void Main(string[] args)
    {

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

        List<Department> departments = new List<Department>()
        {
             new Department {DEPT_ID=101,   DEPT_Name="HR        "   },
             new Department {DEPT_ID=102,   DEPT_Name="ACCOUNTS  "   },
             new Department {DEPT_ID=103,   DEPT_Name="SALES     "   },
        };

        var ResultQuery = (from emp in employees
                           join dept in departments
                           on emp.DEPT_ID equals dept.DEPT_ID
                           where emp.Salary>3000
                           select new
                           {
                               ID = emp.ID,
                               Name = emp.Name,
                               Salary = emp.Salary,
                               DeptName = dept.DEPT_Name
                           }
                           ).ToList();


        Console.WriteLine("Employee Details: ");
        foreach (var e in ResultQuery)
        {
            Console.WriteLine("\tID: " + e.ID + ", Name: " + e.Name + ", Salary: " + e.Salary + ", Department: " + e.DeptName);
        }
    }
}
Employee Details:
        ID: 101, Name: Amit  , Salary: 4000, Department: HR
        ID: 102, Name: Amit  , Salary: 3800, Department: ACCOUNTS
        ID: 103, Name: Salman, Salary: 3500, Department: SALES
        ID: 105, Name: Shyam , Salary: 7000, Department: ACCOUNTS
        ID: 106, Name: Kishor, Salary: 5000, Department: SALES
Press any key to continue . . .

Final Words

We hope that you and your doubts have been resolved through the article C# program to join Employee and Department class and employee’s salary must be greater than 3000 using Linq. And if you have any doubts let us know via the comment box. We cater to your doubts. And if you liked this article, we ask you to share it with your friends.

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

Share on:

Leave a Comment