It's a beautiful, beautiful world with LINQ and Lambda Expressions!

by Dmitry [dimaka] Pavlov 10. March 2010 23:33

I like C# for a long time. And now I like it even more once I have tried LINQ extension introduced in .NET Framework 3.5. And even more with combination LINQ with Lambda Expressions (anonymous functions).

I won't write ABOUT a lot, just some lines of code:

Example 1: Filter and sort collection

List<Entry> entries = Entries.FindAll(
 e => e.IsPublished && e.Type == EntryType.NewsPost);
entries.Sort((x, y) => y.DateCreated.CompareTo(x.DateCreated));

Example 2: Filling DropDownList control with items

ddlParent.Items.AddRange(Entry.Entries.FindAll(e => e.Id != id)
    .ConvertAll(e => new ListItem(e.Title, e.Id.ToString())).ToArray());

I like it!

Tags:

.NET | Tips | Lambda | LINQ

Comments

Add comment




  Country flag

biuquote
  • Comment
  • Preview
Loading



Calendar

<<  August 2010  >>
MoTuWeThFrSaSu
2627282930311
2345678
9101112131415
16171819202122
23242526272829
303112345

View posts in large calendar