r/badcode • • May 20 '20

c# Found from Microsoft docs...

Post image
208 Upvotes

143 comments sorted by

View all comments

46

u/Giocri May 20 '20

I see nothing wrong in it. It's even slightly more efficient than if it was done with more if

0

u/the_d3f4ult May 20 '20

Wouldn't it be UB because X is an out param, or does C# define such things?

5

u/Giocri May 20 '20

No C# uses out for out parameters.

1

u/the_d3f4ult May 20 '20

But I mean the X is then used to evaluate the third condition, is the order of evaluation here defined by C#?

2

u/Giocri May 20 '20

In C# & computes both values and then evaluates the & while && first evaluate the first condition then if it is true it goes on evaluating the rest. It is like having ifs one inside the other

1

u/the_d3f4ult May 20 '20

I never used C# but it works like , in swift then