Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

how would I use lambda expression to get all names in the listwith the name Joe and return to screen. i tried doing so but


how would I use lambda expression to get all names in the listwith the name Joe and return to screen. i tried doing so but i dontget it returned to screen. images at bottom of screen

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;

namespace LambdaAssignment{ class Program { static void Main(string[] args) { ///List witheach element of type empinfo ListEmployees = new List() { //creating ourlist with values given to name and id new empInfo{ Name = "Guido Mista", ID = 1 }, new empInfo{ Name = "Jotaro Kujo", ID = 2 }, new empInfo{ Name = "Joseph Joestar", ID = 3 }, new empInfo{ Name = "Sasuke Uchiha", ID = 4 }, new empInfo{ Name = "Joe Kim", ID = 5 }, new empInfo{ Name = "Giorno Giovanna", ID = 6 }, new empInfo{ Name = "Trisha Una", ID = 7 }, new empInfo{ Name = "Joe Hughs", ID = 8 }, new empInfo{ Name = "Ninel Rich", ID = 9 }, new empInfo{ Name = "Sakura Hataka", ID = 10 }

};

var Employee1 =Employees.FindAll(x => x.Name == "Joe");

foreach (var employeesin Employee1) { Console.WriteLine(employees.Name); }

//this will retrievethe employees with id greater than 5 var Employee =Employees.FindAll(x => x.ID > 5); foreach (var emp inEmployee) { //will displaythose with id greater than 5 Console.WriteLine(emp.Name); } Console.ReadKey();

} }}

image

image

ram 2 3 4 6 7 8 9 0 2 3 4 Program.cs 5 6 17 18 19 20 21 22 23 24 25 26 27 28 29 38 31 32 38 34 35 36383948123445 30 33 36 37 40 M Main(string[] args) using System; using using System.Linq; using System.Text; using System.Threading.Tasks; empinfo.cs System.Collections.Generic; namespace LambdaAssignment { class Program { static void Main(string[] args) ///List with each element of type empinfo List Employees = new List () { //creating our list with values given to name and id }; new empInfo Name = "Guido Mista", ID = 1 }, new empInfo Name = "Jotaro Kujo", ID = 2 }, new empInfo Name = "Joseph Joestar", ID = 3 }, new empInfo Name = "Sasuke Uchiha", ID = 4 }, new empInfo (Name = "Joe Kim", ID = 5 }, new empInfo new empInfo new empInfo new empInfo Name = "Giorno Giovanna", ID = 6 }, Name = "Trisha Una", ID = 7 }, Name = "Joe Hughs", ID = 8 }, Name = "Ninel Rich", ID = 9 }, new empInfo (Name = "Sakura Hataka", ID = 10 } var Employeel = Employees.FindAll(xx.Name == "Joe"); } foreach (var employees in Employee1) { Console.WriteLine (employees.Name); //this will retrieve the employees with id greater than 5 var Employee Employees.FindAll(x = x.ID > 5); foreach (var emp in Employee) { //will display those with id greater than 5 Console.WriteLine(emp. Name); Console.ReadKey();

Step by Step Solution

3.38 Rating (151 Votes )

There are 3 Steps involved in it

Step: 1

You can use a lambda expression and LINQ to filter the list of names by the ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions