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!