Ebbe Kristensen wrote:
Peter Bromberg [C# MVP] wrote:
>To simplify:
string address = String.Empty
Now "address" is not unassigned.
Correct - and sub-optimal because now 'myMLst.Add()' will have to contain a
check for an empty address, a check that already has been performed in the
preceding if-statement.
Why would you say that? The check in the if() statement doesn't check
the variable, it checks the database row. The statement using the
variable executes whether the database row includes that value or not.
It's a bug to execute that line of code without initialization the
variable first.
Now, it may well be a bug to execute the line of code when the database
row's value is missing as well. But that's a separate issue; the code
posted has clear semantics, even if they are wrong. You can't just go
making changes to the basic behavior of the code, not without confirming
with the OP that that's a reasonable thing to do.
Pete