Showing posts with label System.Linq. Show all posts
Showing posts with label System.Linq. Show all posts

Tuesday, December 27, 2022

linq query to get maximum salary in employee list object

 Here is an example of how you could use LINQ (Language Integrated Query) to get the maximum salary in a list of employee objects in C#:


  using System.Linq;


// Assume that the list of employees is stored in a variable called "employees"


// Get the maximum salary from the list of employees

decimal maxSalary = employees.Max(e => e.Salary);


// You can also use the following syntax to achieve the same result:

// decimal maxSalary = (from e in employees select e.Salary).Max();



In this example, the Max method is used to get the maximum salary from the list of employees. The method takes a lambda expression that specifies the property to use for the comparison (in this case, the Salary property).


Alternatively, you can use a LINQ query to achieve the same result. The query uses the from and select clauses to specify the source collection and the property to select, and the Max method is used to get the maximum value.


Note that this code assumes that the employees list and the Employee class have already been defined and that the Employee class has a Salary property of type decimal. You will need to modify the code to match the structure of your own data.

ASP.NET Core

 Certainly! Here are 10 advanced .NET Core interview questions covering various topics: 1. **ASP.NET Core Middleware Pipeline**: Explain the...