Write a LINQ query that selects all the Employees from the array in Fig. 11.4 wi
ID: 3547253 • Letter: W
Question
Write a LINQ query that selects all the Employees from the array in Fig. 11.4 with salaries greater than $4000. Then determine how many Employees are in the result and calculate the average of those salaries.
Figure 11.4
Dim employees() As Employee = {
New Employee("Jason", "Red", 5000D),
New Employee("Ashley", "Green", 7600D),
New Employee("Matthew", "Indigo", 3587.5D),
New Employee("James", "Indigo", 4700.77D),
New Employee("Luke", "Indigo", 6200D),
New Employee("Jason", "Blue", 3200D),
New Employee("Wendy", "Brown", 4236.4D)}
Explanation / Answer
Hi,
You can write the linq Querries as below to get employees that are above $4000 salary count and average of employees where salary greater than $4000.
Dim query = From e In Employee _
Where e.Salary > 4000
Dim Count = query.Count() //To get Count of employees where salary is > 4000
Dim Average = (From emp In query _
Select emp.Salary).Average()
// To Get Average of salary where sal > 4000
Regards
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.