.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> C# >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Using Lambda expression in FindAll()

Posted By:Dhananjay Kumar       Posted Date: October 05, 2010    Points: 30    Category: C#    URL: http://www.dotnetspark.com  

Using Lambda expression in FindAll(). In this article we will see how to use 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



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 lst = new List();
            lst.Add(20);
            lst.Add(300);
            lst.Add(400);
            lst.Add(9);
            lst.Add(19);
            lst.Add(789);
            lst.Add(45);

            List lstgrthund = lst.FindAll(a=>a>100? true:false);            

            foreach (var r in lstgrthund)
            {
                Console.WriteLine(r);

            }
            Console.ReadKey(true);            

        }
    }
}

Output



 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend