Find dead .NET code

Skip to end of metadata
Go to start of metadata

Redirection Notice

Icon

One benefit of using ReSharper is that it shows you bits of your own code that you’re not using. ReSharper is actually very smart about it: not only will it point out code that isn’t used anywhere, but it will detect more complicated cases – for example the case where a field is both declared and initialized, but nothing apart from initialization actually happens to it.

Let’s take a look at an example. Say we have a class Person defined as follows:

Now, ReSharper will indicate that the name field isn’t used. If you hover the mouse pointer over the name field, you’ll get the following message:

If you now move the caret over the name field, ReSharper will offer an option to remove the name field and any assignment to it:

After you pick the removal option, ReSharper informs you that the assignment will also be removed:

And here is the end result:

Notice that now ReSharper informs us that the parameter can also be removed. We use a corresponding context action:

And we get an empty constructor which, as you may have guessed, is also not needed, since a default constructor is implemented by default. Once again, ReSharper picks up on it and offers us an option to get rid of the constructor:

  • No labels