+ Reply to Thread
Results 1 to 5 of 5

Thread: What are lambda expressions?

  1. #1
    Join Date
    Mar 2009
    Posts
    1,375
    Rep Power
    24

    Cool What are lambda expressions?

    What are lambda expressions?
    This is a question I got from Siten some time ago. I wont hide that I hate this one topic. Here are some code shortages you can get by using lambdas.

    Lambdas are used instead of delegates, as shortened replacement for them. Many possible usages of lamdas lie in methods of collections, when you want to select some elements, or check is some element or all elements comply with your demands. For a start we need a list:

    Code:
        List<stringoriginalList = new List<string>()
        {
            
    "123a""""aabb""zzxxa""ccccdd""so on a""etc""...a",
        }; 
    Then we can use lambda expressions with methods that require delegates. For example Find, FindAll, Exists, TrueForAll as well as Any, All and some others. The examples below do the same, the only difference is that lambdas-code is shorter and more readable.

    Code:
        List<stringselectiveInclusion 
            
    originalList.FindAll(new Predicate<string>(delegate(string everyobj)
                {
                    return 
    everyobj.Contains("a");
                }));

        List<
    stringselectiveInclusion2 =
            
    originalList.FindAll( (string everyobj) =>
                {
                    return 
    everyobj.Contains("a");
                }); 
    Here is another example of lambdas. The difference is the same, in the line of method call.

    Code:
        bool isThere123 
            
    originalList.Exists(new Predicate<string>(delegate(string s)
                {
                    return 
    == "123a";
                }));

        
    bool isThere123lambda 
            
    originalList.Exists( (string s) =>
                {
                    return 
    == "123a";
                }); 
    The full source code is attached. Feel free to play with it.
    Regards,
    Arek Bulski.
    Attached Files Attached Files

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2006
    Location
    Amherst, New York, United States
    Posts
    6,277
    Blog Entries
    26
    Rep Power
    20

    Re: What are lambda expressions?

    I still haven't figured out what lambda expressions have to do with lambda calculus?

  4. #3
    Join Date
    Mar 2009
    Posts
    1,375
    Rep Power
    24

    Re: What are lambda expressions?

    Quote Originally Posted by John View Post
    I still haven't figured out what lambda expressions have to do with lambda calculus?
    There is some explanation on Wikipedia. I dont understand English well enough to understand it though. Lambda calculus - Wikipedia, the free encyclopedia

  5. #4
    Jordan Guest

    Re: What are lambda expressions?

    Just read this one. Never even saw it before now. Nice tutorial, +rep.

  6. #5
    Join Date
    Mar 2009
    Posts
    1,375
    Rep Power
    24

    Re: What are lambda expressions?

    Thank you, Jordan. Do you think many people just do not use Lambda expressions at all?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Lambda expression
    By Tonchi in forum C# Programming
    Replies: 3
    Last Post: 09-20-2011, 12:44 PM
  2. Intermediate c# introduction to lambda functions and LINQ
    By chili5 in forum CSharp Tutorials
    Replies: 3
    Last Post: 08-17-2011, 06:26 PM
  3. Intermediate JavaScript: Using lambda functions
    By dbug in forum JavaScript Tutorials
    Replies: 0
    Last Post: 09-11-2010, 03:14 PM
  4. What is a Lambda in programming?
    By tobro in forum Programming Theory
    Replies: 5
    Last Post: 09-05-2010, 06:23 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts