The requested page is not available for the requested platform. You are viewing the content for Default platform.

Delegate can be replaced with lambda expression

CodeRush Classic shows the Delegate can be replaced with lambda expression code issue if a delegate is used in an anonymous method declaration.

Fix

Use a lambda expression instead of the delegate.

Purpose

The use of lambda expressions improves your code readability, because of its compact notation.

Example

Func<Array, int> getLastIndex = delegate(Array arr){ return arr.Length - 1; };

Fix:

Func<Array, int> getLastIndex = arr => arr.Length - 1;