Using Lambda Expression in FindAll()

I got a critical comment from @amazedsaint.  You can read his blog http://amazedsaint.blogspot.com/

If you read my previous post http://dhananjaykumar.net/2010/10/01/findall-finding-multiple-items-in-c-list/, 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 

1.gif
 
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 
 
2.gif

Up Next
    Ebook Download
    View all

    milton

    Read by 0 people
    Download Now!
    Learn
    View all