Quantcast
Channel: YouTrackReSharper (RSRP) - Bug and Issue Tracker
Viewing all articles
Browse latest Browse all 106942

RSRP-288336: 'Convert part of body into Linq expression' could avoid casting

$
0
0
Reporter Drew Noakes (drewnoakes) Drew Noakes (drewnoakes)
Created Feb 16, 2012 12:26:07 AM
Updated Feb 20, 2012 6:31:47 PM
Priority Normal
Type Feature
Fix versions No Fix versions
State Submitted
Assignee Unassigned
Subsystem No subsystem
Affected versions 6.1
Fixed in build No Fixed in build
foreach (MainMenuItem item in Items)
{
    if (item.Content is Menu)
    {
        ((Menu)item.Content).Hide();
    }
}


R# turns out:

foreach (MainMenuItem item in Items.Where(item => item.Content is Menu))
{
    ((Menu)item.Content).Hide();
}


But in fact a simpler result would be:

foreach (Menu item in Items.Select(item => item.Content).OfType<Menu>())
{
    item.Hide();
}

Viewing all articles
Browse latest Browse all 106942

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>