Anonymous Methods and LinQ

LinQ provides query language for our collections as far as I understood,

And by the way in c# 2.0  there is Anonymous methods which provide us using closures as functors.

Did anybody have issues with Anonymous methods Why did they introduce LinQ

what is the best way to select elements of a list that satisfy a given predicate LinQ or Anonymous Methods using closure

sorry I am kind of confused.



Answer this question

Anonymous Methods and LinQ

  • Ken Mingeaud

    Doh!  Yes indeed, meant to say "less cleaner".  Thanks.


  • abcdfrx

    Linq is a pattern that makes the use of such methods much easier.  If Linq is available, I see no reason to write the methods by hand.

  • Aleksey Tsingauz

    thansks for the feed back.

    I am evaluting an object database db40 which has a really closer syntax, to linQ may be one day ms will look at the object database market


  • Darren Shaffer

    I personally prefer the terseness lambda syntax over anonymous methods.

    This:

    Customer bob = customers.Find(delegate(Customer c)
       {
          return c.Name == "Bob";
       });

    feels much less cleaner to me than:

    Customer bob = customers.Find(c => c.Name == "Bob");

    A deeper boon of lambda expressions stems from the ability to convert lambda expressions into expression trees.  There are tremendous benefits for doing things like creating strongly-typed query languages for data mappers where before the only option was to represent query syntax as strings. 

    Ultimately, I think LINQ would be darned painful if every lambda in an expression of use of Sequence would have to be coded as an anonymous method.  Even mildly complex queries would become quite hard to read rather quickly.

    -Scott


  • Johnny_R2

    Don't you mean "feels much less cleaner than"...

  • Anonymous Methods and LinQ