I’ve talked a lot about Resharper features such as the Find Usages, live templates, and the instant code . But I have not talked about some of the features that are not as prominent but I find especially helpful. So here are a few very simple tips for how to clean your code up using Resharper.

Tip 1) Removing redundant “this” qualifier

Sometimes I add the this statement when I am writing code. It is a habit I got into a long while ago and have had a hard time breaking. I prefer to not have “this.” leading all of my class level properties and methods. Resharper makes this easy to fix. Just remember this sequence:

  1. F12
  2. ALT + ENTER
  3. ENTER

F12 brings you to the next Resharper warning (or Error). In this case, you will see the “this.” statement (grayed out because it is redundant)

ALT-ENTER displays the Resharper hint window (or you can click the red light bulb)

ENTER removes the redundant qualifier.

Tip 2) Removing Unreachable Code

This same process works for removing unreachable code.

  1. F12
  2. ALT + ENTER
  3. ENTER

So this code is the before:

And this code is after:

Tip 3) Removing Redundant Type Arguments

Sometimes you have methods that accept a type using Generics. And sometimes specifying the type is redundant. Resharper let’s you find these, by, guess what, using:

  1. F12
  2. ALT + ENTER
  3. ENTER

So this …

becomes this

Tip 4) Redundant Using Directives

I like to clean up my Using statements at the top of my class files. It seems some files, like when you create a new Page, have tons of extra “Using” statements. Yes, maybe I’ll need them, but even I do, I’ll let Resharper or Visual Studio’s tools tell me. So let’s get rid of them.

First, I hit the CTRL + HOME keys to go to the top of the page.

Then comes the common sequence:

  1. F12
  2. ALT + ENTER
  3. ENTER

So this …

becomes this:

I love it!

Tip 5) Property Accessors

When I create public properties sometimes I forget to make the set accessor private. Do I need to? No, but why expose something that does not need to be exposed. Resharper makes this easy again:

  1. F12
  2. ALT + ENTER
  3. ENTER

So this

becomes this

There is so much you can do with Resharper but hopefully this shows you how easy it is to tackle some small refactoring jobs to reduce some code in your project.