Do the following 2 code snippets achieve the same thing?
My original code:
if (safeFileNames != null)
{
this.SafeFileNames = Convert.ToBoolean(safeFileNames.Value);
}
else
{
this.SafeFileNames = false;
}
What ReSharper thought was a better idea:
this.SafeFileNames = safeFileNames != null &&
Convert.ToBoolean(safeFileNames.Value);
I think the above code is much easier to read, any compelling reason to change it? Would it execute faster, and most importantly, will the code do the exact same thing?
Also if you look at the : Convert.ToBoolean(safeFileNames.Value); section, then surely this could cause a null reference exception?
this.SafeFileNames = bool... Local safeFileNames is a strongly typed custom object, here is the class:
public class Configuration
{
public string Name
{
get;
set;
}
public string Value
{
get;
set;
}
}