0

I am new to ReSharper and have integrated with Visual Studio 2010. I have found a suggestion in the code as follows,

string query;
query = "SELECT * FROM Employee";

The ReSharper tool asked me to change the above code to

const string query = "SELECT * FROM Employee";

What is the performance benefit i get from this?

Saravanan
  • 7,637
  • 5
  • 41
  • 72

1 Answers1

2

Almost certainly very little (or none), but the code is more correct (if the string is not being reassigned, which ReSharper has determined it not to be).

After all, it's easier to sleep at night with clean code! ;)

Mitch Wheat
  • 295,962
  • 43
  • 465
  • 541
  • 1
    Indeed, not every change proposed by Resharper is for performance reasons. In the end, clean code leads to better maintainability. Hence, don't let Resharper fool you. For instance, it can spit out some complex Linq-queries for foreach-loops that might be one-liners, but are so illegible you better leave the foreach as it stands. – sanderd May 02 '11 at 10:51
  • so you say that making the string as a constant using `const` is a bit performance improvement. Let me take that, I have asked in my previous posts about how to find the memory usage by a .net application and which statements / loops are memory intensive etc. no replies.. could you guide me in this regard. – Saravanan May 02 '11 at 12:27