2

I have been writing String.IsNullOrEmpty for years, and in Visual Studio 2015, the IDE suggests to refactor it into string.IsNullEmpty, Why? what would you do?

I well understand what behind String and string, however, I just wonder why VS 2015 could give me a hint I don't need.

ZZZ
  • 2,752
  • 2
  • 25
  • 37
  • 1
    `String` and `string` are synonyms, so I don't know why it tells you that, since they really point to the same type, one can't be better than the other. See http://stackoverflow.com/questions/7074/whats-the-difference-between-string-and-string – Ron Beyer Oct 01 '15 at 03:24

2 Answers2

7

It's due to a "Code Style" option, under:

Tools / Options / Text Editor / C# / Code Style

Uncheck the following option, and it should stop warning you.

enter image description here

If you find the styles useful, in that they force a certain uniformity on your code that you like to be warned about, then leave it checked. Personally, I'd just uncheck it.

Grant Winney
  • 65,241
  • 13
  • 115
  • 165
2

The IDE suggests to refactor it into string.IsNullEmpty, Why?

Actually there is no difference between String and string since both are same and string is just an alias. If VS still complaining about re-factoring it then probably because of some FxCop code analysis rules. You may want to verify the same.

In one of my work experience, they had a FxCop custom rule setup to use the actual Type name instead of alias like use String instead of string (OR) Int32 instead of int.

Rahul
  • 76,197
  • 13
  • 71
  • 125