Do the following 2 code snippets to achieve the same?
My source code:
if (safeFileNames != null) { this.SafeFileNames = Convert.ToBoolean(safeFileNames.Value); } else { this.SafeFileNames = false; }
What ReSharper thought was the best idea:
this.SafeFileNames = safeFileNames != null && Convert.ToBoolean(safeFileNames.Value);
I think the above code is much easier to read, any good reason to change it?
Will it run faster, and most importantly, will the code do the same?
Also, if you look at the section: Convert.ToBoolean(safeFileNames.Value); , then this can lead to the exclusion of a null reference?
this.SafeFileNames = bool
Local safeFileNames is a strongly typed user object, here is a class:
public class Configuration { public string Name { get; set; } public string Value { get; set; } }
c # if-statement
Jl.
source share