Cleaning a handful of warnings on a C# project I have inherited, I found this code snippet:
private bool _WriteValue(object FieldValue,..,..)
...
if(MultipFactor!=1)
FieldValue=((double)FieldValue)*MultipFactor;
else
FieldValue=FieldValue;
I've obviously burninated the else block without thinking too much, just wondering why the previous programmer has left that part.
In your opinion, are there any valid circumstances where foo=foo makes sense?
Some more details on the _WriteValue method:
The _WriteValue method is wrapped into different overloaded WriteValue methods that pass to the object FieldValue parameter, values of the following types: int, long, string and Datetime.
If FieldValue is a property, the set operator could trigger some code, so a self-assignment could make sense in such a case?!
An example would be:
public string FieldValue
{
get
{
return _fieldValue;
}
set
{
_fieldValue = value;
Trace.WriteLine( string.Format("Received value '{0}'.", value ) );
}
}
(My answer was given before the poster added the information that FieldValue actually is a method parameter, not a property as I assumed first)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With