unused methods RRS feed

  • Question

  • User1144299848 posted

    Hi folks,

    I am a amateur code writer drinking from this knowledge fountain to improve myself.

    A new learned technique improve the part of code I am using and turn 'obsolete' the older one, hence I current have many methods that are not in use anymore, with no reference to it in the whole solution. This problem turn the code dificult to mantain.

    Is there a way VS can tell which methods are not been used so I can choose to delete or keep it.




    Moises Durovni

    Sunday, October 6, 2013 6:44 PM


  • User281315223 posted

    Sadly, you'll likely need to use a third-party or extension to Visual Studio to handle this, but don't worry it certainly can be done.

    Using Resharper

    Resharper is an incredible development tool that offers a free 30-day trial that you could use and it does a heck of alot more than just detect dead code. It provides its own Intellisense, offers improvements over existing code and helps you write cleaner and more maintainable code.

    Within Resharper, there is an option called "Analyze Errors in Solution" option within Resharper, which can be enabled through the Resharper status bar (right-click on the Resharper icon).

    After that is enabled, right-click on your project or solution and select "Find Code Issues". You should see a "Unused Symbols" tab within the results that will contain unused classes, methods and members. (It should say "Type or Member is never used")

    Using FxCop

    You can also use Microsoft's FxCop tool to perform code analysis and find "dead code" within your applications. You can find a post here that details installing it if you aren't using at least Visual Studio 2010 Premium or Ultimate (It is integrated in newer versions of Visual Studio under the Code Analysis option.)

    Using NDepend

    NDepend is another tool that can help suggest and find unused methods as well as optimize some of your existing code that you might want to consider trying as well.

    Related Suggestions and Discussions

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, October 6, 2013 9:35 PM