Blog

Select query in lambda in C#

Lambda

Select query in lambda in C#

  1. Create a console application and create a list of customers in it.
				
					           var customerList = new List<Customer>()
            {
                new Customer{CustomerCode=101,CustomerName = "Steve"},
                new Customer{CustomerCode=102,CustomerName = "Mark"},
                new Customer{CustomerCode=103,CustomerName = "Bill"},
                new Customer{CustomerCode=104,CustomerName = "Dell"}

            };
				
			

2. Now with the help of Lambda expression, select the list of customer codes from the customerList

				
					var result = customerList.Select(a => a.CustomerCode).ToList();
				
			

3. Now in the “a” we will get all the codes in the customerList

4. Now we will loop through the customerList to get it printed

				
					        var result = customerList.Select(a => a.CustomerCode).ToList();
            result.ForEach(a => Console.WriteLine(a));
            Console.ReadLine();
				
			
dotnetcoaching

Please commecnt about how we can modify the post for better and please share the post so the dotnercoaching can be more accessable and you become a part of our mission to spread free knowledge to make a better future.

Subhajit
maxcoach-shape-01
maxcoach-shape-02

Free 10 Days

Master Course Invest On Self Now

Subscribe & Get Your Bonus!
Your infomation will never be shared with any third party