Sometimes you can write it better than Resharper

Here is a real-life example of when people are much better expressing intent than a tool: Consider the following code from a typical Silverlight Navigation application:

foreach (UIElement child in LinksStackPanel.Children)
{
 var hb = child as HyperlinkButton;
 if (hb != null && hb.NavigateUri != null)
 { .. }
}

Resharper proposed to write this as following:

foreach (var hb in LinksStackPanel.Children
 .Select(child => child as HyperlinkButton)
 .Where(hb => hb != null && hb.NavigateUri != null))
{ .. }

Here is what i wrote instead:

foreach (var hb in LinksStackPanel.Children
 .OfType<hyperlinkButton>()
 .Where(hb => hb.NavigateUri != null))
{ .. }

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>