r/badcode • • Jul 08 '19

c# While reviewing code today...

Post image
696 Upvotes

57 comments sorted by

View all comments

0

u/[deleted] Jul 08 '19

[deleted]

59

u/botle Jul 08 '19

As someone that doesn't do C#, I find that completely terrifying.

36

u/pipe01 Jul 08 '19

You can do horrifying stuff in any language, C# just makes this a bit easier

6

u/[deleted] Jul 09 '19

You can have setters with side effects in like any language.

11

u/jarfil Jul 08 '19 edited Dec 02 '23

CENSORED

7

u/Tyfyter2002 Jul 08 '19

Properties in C# are basically a midpoint between fields and methods (with a few added benefits from what I've heard) so you can just use them for the intended purpose, or use them to replace any method with one of the following (as long as you don't intend to use it as a delegate): a void return type (set, probably with an array of objects), no arguments (get, also probably the intended purpose), or multiple arguments and a non-void return type (set, although it functions more similarly to using reference arguments).

3

u/christian-mann Jul 09 '19

You could do that in Python, C++, and probably Javascript as well.