Detect dead code in C#

ReSharper can handle that. You could also check out NDepend.

If you don't feel like paying for either of those, I believe you can analyze your project with FxCop and it will also identify dead code.


Compile your code and check the warnings in the Error List. The following code:

    public ActionResult Index() {
        ViewData["Message"] = "Welcome to ASP.NET MVC!";
        return View();
        return null;  // unreachable
    }

produces this warning:

Warning 11  Unreachable code detected   <fullpath>\HomeController.cs    13  13  <prjname>

Tools like JetBrains ReSharper (http://jetbrains.com/resharper)* can also perform this analysis on the fly and highlight dead code.

* ReSharper is a commercial tool.


Resharper identifies dead code and unused parameters/locals and so does FxCop.