Home » Code | ASP.NET

I Luv Lambdas

23. April 2009 by thebeebs 0 Comments

Lambdas sound like a type of curry, however the only similarity that these beauties have with Indian food are that they’re hot!

Day by day I’m finding lambdas  more and more useful. I used to only use them when I was querying the entity framework but I'm finding that I'm constantly falling back on them as a concise and simple way to deal with generic collections.

Today I had a problem that I wanted to solve with out the need to generate too much code or create a custom collection.

image

All I wanted to know was if my products attribute collection had attributes who’s first Item was a provider with the Id of x.

Lambda enabled me to get this information out and loop through it with just a couple of lines of code.

foreach (IDataTransferAttributeItem attributeItem in product.Attributes.Where(a => a.Providers.First().Id == this.providerId))
                  {
                   // TODO: Do something with attributeItem
                  }

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading