I want to remove the warning in the following code that will be warned by Resharper as "Redundant 'string.Format' call".
Debug.WriteLine(string.Format("Test Data Value: {0}", data));
I think everything with Debug class will not be included in release Mode by compiler and Debug will be used only in Debug mode.
So why Resharper cares about string.Format if it will be removed anyway.
But this code will work even though in Release mode both will be warned.
string message = string.Format("Test Data Value: {0}", data);
Debug.WriteLine(message);
The code above will not be warned by Resharper but message variable will become a trash in release if is not optimized.
I ask this question because there are a lot of such code and if I use "Suppress inspection" then the code will be bigger and not clean.
How to remove the warning?
Although you can, of course, suppress the warning - ReSharper is very flexible in terms of telling it to "shut up".
However, I'd say, ReSharper is a little helpful here. The string.Format
is very redundant for the simple reason is that Debug.WriteLine
has an overload which mimics the same thing:
http://msdn.microsoft.com/en-us/library/cc190153(v=vs.110).aspx
I'd suggest a better solution would be to replace your uses of Debug.WriteLine(string.Format(....));
with Debug.WriteLine("Test Data Value: {0}", data)
.