Home
Do you import namespaces and shorten the references?
  v1.0 Posted at 26/04/2018 8:44 AM by Tiago Araujo
You should import namespaces and shorten the references.

​System.Text.StringBuilder myStringBuilder = new System.Text.StringBuilder();

Figure: Bad code - Long reference to object name​​

using System.Text;
...
...
StringBuilder myStringBuilder = new StringBuilder();

Figure: Good code - Import the namespace and remove the repeated System.Text reference


If you have ReSharper installed, you can let ReSharper take care of this for you:

ReSharperReformatCode.gif
Figure: Right click and select "Reformat Code..."
ReSharperShortenReferences.gif
Figure: Make sure "Shorten references" is checked and click "Reformat"​
​​

Related rules

    Do you feel this rule needs an update?

    If you want to be notified when this rule is updated, please enter your email address:

    Comments:

    Note: Social Media login for Yotpo is not working in IE or Safari, please use Chrome. We are waiting for Yotpo to fix it.