Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7928991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:55:13+00:00 2026-06-03T19:55:13+00:00

A coworker of mine started with this code: var newList = new List<>(); foreach(var

  • 0

A coworker of mine started with this code:

var newList = new List<>();

foreach(var item in otherList)
{
    newList.Add(GetNewObjectFrom(item));
}

ReSharper correctly identified a use of LINQ here, and changed it to:

var newList = otherList.Select(o => GetNewObjectFrom(o)).ToList();

However, the lambda is unnecessary, and could be simplified further by just passing the method:

var newList = otherList.Select(GetNewObjectFrom).ToList();

My question:

Can any tool within Visual Studio 2010 Professional, or various arm-twisting of ReSharper, detect this change that should be made? I realize that the best tool is a second set of human eyes, and that’s where this question comes from to begin with … but the more of my job that’s done by computers, the better.

edit: awesome, it’s a ReSharper bug. Here’s a sample program:

using System.Linq;

namespace ResharperMethodGroupBug
{
    class Program
    {
        static void Main(string[] args)
        {
            var program = new NumberProgram(new NumberProcessor());
            program.Run();
        }
    }

    class NumberProgram
    {
        private readonly INumberProcessor numberProcessor;

        public NumberProgram(INumberProcessor numberProcessor)
        {
            this.numberProcessor = numberProcessor;
        }

        static long SquareNumber(int n)
        {
            return n * n;
        }

        public void Run()
        {
            var listOfNumbers = Enumerable.Range(1, 100).ToList();

            // appropriately triggers "convert to method group"
            var listOfSquares = listOfNumbers.Select(n => SquareNumber(n));

            // does not trigger "convert to method group" when it should
            var listOfCubes = listOfNumbers.Select(n => this.numberProcessor.CubeNumber(n));

            // proof that a method group works here
            var anotherListOfCubes = listOfNumbers.Select(this.numberProcessor.CubeNumber);
        }
    }

    interface INumberProcessor
    {
        long CubeNumber(int n);
    }

    class NumberProcessor : INumberProcessor
    {
        public long CubeNumber(int n)
        {
            return n * n * n;
        }
    }
}

edit 2: I’ve posted an issue on JetBrains’ Youtrack: http://youtrack.jetbrains.com/issue/RSRP-301259

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T19:55:14+00:00Added an answer on June 3, 2026 at 7:55 pm

    Resharper already detects this and suggest the simplification:

        static void Main(string[] args)
        {
            var items = new[] { 1, 2, 3 };
            var list = items.Select(i => Foo(i)).ToList(); // R# suggests "Convert to method group"
        }
    
        static int Foo(int i)
        {
            return i;
        }
    

    (tested with VS2010 Pro SP1 and R# 5.1.3)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A coworker of mine was looking through one of our inherited code bases and
A coworker of mine came across this the other day while we were working
A coworker of mine has this problem, apparently after installing Re#, which seems totally
Recently a co-worker of mine wrote in some code to catch a null pointer
My coworker suggested making several of the Eclipse code-formatting and warning settings to be
A coworker recently showed me some code that he found online. It appears to
A coworker's typo when calling a subref raised this strange syntax question. If I
My coworker did this experiment: public class DoubleDemo { public static void main(String[] args)
I was told this by a coworker, and I was curious if this was
A coworker of mine was working on preventing duplicate form submissions (on a successful

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.