ReSharper
 
Get ReSharper
Get your hands on the new features ahead of the release by joining the Early Access Program for ReSharper 2025.1! Learn more

Find dead .NET code

Last modified: 25 September 2024

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 over this field, you’ll get the following message:

ReSharper detects unused field

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

ReSharper detects unused field

And here is the result:

ReSharper detects unused field

Notice that now ReSharper informs us that the parameter can also be removed. We use the corresponding quick-fix:

ReSharper detects unused field

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:

ReSharper detects unused field