Archive

Posts Tagged ‘Delegates’

The Introduce ForEach Action refactoring

August 28th, 2012 1 comment

It is a rather trivial task to iterate over each item of the generic List using a foreach-loop as follows:

ForEach-loop iteration

Read more…

Declare Delegate CodeRush code provider

June 1st, 2012 Comments off

A delegate is a special kind of object that holds a reference to a method. Once a delegate is assigned a method, it behaves exactly like that method. It can have parameters and a return value. Using a delegate allows the programmer to encapsulate a reference to a method inside a delegate object.

Read more…

Refactorings for anonymous methods and lambda expressions

September 27th, 2011 Comments off

An anonymous method is a method without a name – which is why it is called anonymous. You don’t declare anonymous methods like regular methods. Instead, they get declared right inside a member as an inline code block. This is one of the greatest benefits of an anonymous method – it removes the requirement to create a named method elsewhere in the code, especially for simple operations. For example, you are able to pass an inline anonymous method as a delegate parameter, which means that you can use anonymous methods anywhere a delegate type is expected:

Refactor! Anonymous method sample code

Read more…