>Using VS05 and C#. The following two examples produce different results. My goal is to fill myvar with either myvar1 or myvar2. Sometimes my myvar1 is empty, in which case I want the value in myvar2.
>
>When I step through my code in example 1 and myvar1 is empty, the code performs this 'myvar = myvar2' which is what I expect. However, the next line of code then performs this 'myvar = myvar1' which I don't expect. Why does this happen?
>
>The only way I can get the results I want is to change example 1 to look like example 2. Example 2 works all the time. Why doesn't example 1 work like example 2?
>
>
>//Example 1
>if (myvar1 == "") myvar = myvar2; myvar = myvar1;
>
>//Example 2
>if (myvar1 == "")
> {
> myvar = myvar2;
> }
> else
> {
> myvar = myvar1;
> }
>
>
>Thanks,
>
>Jerry
Never seen this written this way. I would say the second example increases the readabily of the code even if it's more verbose.
If it's not broken, fix it until it is.
My Blog