patterncsharpModerate
Shortening boolean with if statement for document version comparison
Viewed 0 times
booleanshorteningwithstatementversioncomparisonfordocument
Problem
Can this be shortened to one line?
bool areVersionsEqual = documentComparer.Equals(version, imported);
if (areVersionsEqual == false)
{
changedDocument.Add(imported);
}Solution
Sure. Use the Not operator.
To explain a little, it's bad practice to do things like this.
because it's completely equivalent to saying
and can be simplified down to
if (!documentComparer.Equals(version, imported))
{
changedDocument.Add(imported);
}To explain a little, it's bad practice to do things like this.
bool boolean = true;
if (boolean == false)
{
//...because it's completely equivalent to saying
if (true == false)and can be simplified down to
if (false)Code Snippets
if (!documentComparer.Equals(version, imported))
{
changedDocument.Add(imported);
}bool boolean = true;
if (boolean == false)
{
//...if (true == false)Context
StackExchange Code Review Q#74064, answer score: 14
Revisions (0)
No revisions yet.