vendredi 22 mars 2019

isn't the "if" redundant here?

Here is the example:

if (value != ageValue) 
{ 
    ageValue = value; 
} 

I mean, if we assign the value of a variable to another one, why would we need to check if they have anyway the same value? That confuses me. Here is the broader context:

private double ageValue; 

public double Age 
{ 
    get { return ageValue; } 

    set
    { 
        if (value != ageValue) 
        { 
            ageValue = value; 
        } 
    }
} 

Aucun commentaire:

Enregistrer un commentaire