This post originated from an RSS feed registered with Agile Buzz
by Joe Walnes.
Original Post: The power of closures in C# 2.0
Feed Title: Joe's New Jelly
Feed URL: http://joe.truemesh.com/blog/index.rdf
Feed Description: The musings of a ThoughtWorker obsessed with Agile, XP, maintainability, Java, .NET, Ruby and OpenSource. Mmm'kay?
Martin Fowler (obligitary Fowlbot namedrop) recently blogged about the power of closures in languages that support them. It's worth remembering that C# 2.0 has true closure support in the form of anonymous delegates. This includes reading and modifying variables outside the context of the closure - unlike Java's anonymous inner classes.
Just for kicks, I've rewritten all of the examples Martin's Ruby examples in C# 2.0. This makes use of the improved APIs in .NET 2.0 pointed out by Zohar.
Ruby
C# 2.0
def managers(emps)
return emps.select {|e| e.isManager}
end