Using Lambda expression in FindAll in C#

No.of Views1364
Bookmarked0 times
Downloads 
Votes0
By  Dhananjay Kumar   On  04 Oct 2010 10:10:36
Tag : CSharp , How to
Using Lambda expression in FindAll in C#
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Introduction

If you read my previous post http://www.codegain.com/articles/csharp/howto/finding-multiple-items-in-csharp-generic-list.aspx

I am using a method GreaterThanHun As predicate to pass as parameter to FindAll()
Instead of that we can use

1.    Anonymous method
2.    Lambda expression

So, I am going to show you here how we could use Lambda expression

Image Loading

So here we are just writing a lambda instead of calling a function.

Program.cs

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

namespace ConsoleApplication24
{class Program
    {static void Main(string[] args)
        {

            List<int> lst = new List<int>();
            lst.Add(20);
            lst.Add(300);
            lst.Add(400);
            lst.Add(9);
            lst.Add(19);
            lst.Add(789);
            lst.Add(45);

            List<int> lstgrthund = lst.FindAll(a=>a>100? true:false);foreach (var r in lstgrthund)
            {
                Console.WriteLine(r);

            }
            Console.ReadKey(true);            

        }
   }
}

 Output 

Image Loading

Enjoy it.Happy coding thank for reading.

 
Sign Up to vote for this article
 
About Author
 
Dhananjay Kumar
Occupation-Software Engineer
Company-Infosys Technolgies,Pune
Member Type-Gold
Location-India
Joined date-20 Jul 2009
Home Page-http://dhananjaykumar.net/
Blog Page-http://dhananjaykumar.net/
Dhananjay Kumar is Microsoft MVP on connected system. He blogs at http://dhananjaykumar.net/ . You can follow him http://twitter.com/debugmode_/ and reach him at dhananjay.25july@gmail.com
 
 
Other popularSectionarticles
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top