Why does Visual Studio suggest simplifying the names? - IDE0001 Name can be simplified


Visual Studio 2013 suggests simplifying names, as you can see below:

The suggestion is:


IDE0001 Name can be simplified translating: IDE0001 Name can be simplified


        var obj = new Object(); //Sugere a simplicação do Object para object
        var outroObj = new object(); //Tudo ok

        var teste = String.Empty; //Sugere a simplicação do nome String para string
        string teste2 = string.Empty; //Tudo ok
        String teste3 = string.Empty; //Também sugere a simplicação do nome String para string

I've always seen people recommending to use:

string MinhaString = String.Empty;

Now Microsoft recommends:

string MinhaString = string.Empty;

Why this suggestion? What is the advantage?

asked by anonymous 11.08.2015 / 15:48

3 answers



First, String.Empty is the same as "" . Who says it's different, has advantages, does not know the implementation and is inventing things (until it has already been different in the past by implementation internal). What the person can, is to say that it becomes more readable, clearer that you want an empty string to be created there. Some will say that it's easy for you to look at "" and " " and find that it's the same thing. This I can understand. Although I think exaggeration.

Selecting Rules in Visual Studio

You should know that this information can be selectively turned off, right? If you do not like some rule and do not want to follow it, hang up. If you want some of your own, you can add it to the VS code analysis system.

Names rule

There is no difference and it is only a decision that one must take to avoid each one doing his own thing. That's why the rule exists.

I've never been able to find a reason to clearly choose one over the other. Since the language prefers to have an alias for the BCL class, it prefers to use it. Too bad that Microsoft does not follow its codes:)

Use of class names

There is a recommendation to use class names when some class or class member needs to carry the type name. Example: PrintInt32 is better and not Print_int or worse, Printint . So it is easy for other languages that run on top of the CLR to understand what it refers to since int is something exclusive of C # and not platform. Int32 is the type name throughout the CLS . This applies to all language type alias .

In local or even private variable names (may be a problem in case of reflection, but it is rarely problematic) is not a problem and it is preferable to use the name described by the language. In expressions, as in the example of the question, which is something that does not leak for use in other languages, the option is by the form of the language.

Some might find it more consistent to use only the class name since there are cases where it is best. It makes sense, but the option was made back there to make it easier for those coming from C / C ++ / Java.

11.08.2015 / 16:12

To avoid having to use "using System;"

11.08.2015 / 16:18

Since string is an alias (pseudonym) of String , there is only one advantage: consistency.

The rule is to use the aliases of C # ( string , int , long , bool ) instead of .NET types String , Int32 )

11.08.2015 / 16:10