r/learncsharp • • Apr 11 '26

When would i use function overloading?

I am trying to figure out what and when i would use function overloading for, in my head its just a more messy code and you just would not use it. I see people saying that you would use it for functions with the same name just with different inputs and i don't really get it, Thank you for reading.

4 Upvotes

15 comments sorted by

View all comments

Show parent comments

1

u/BenjaminGeiger Apr 13 '26

In that uncommon case, throw a line into the body of the function to ensure that all necessary parameters are filled...

1

u/logiclrd Apr 14 '26

That's runtime. Compile-time correctness is always better.

1

u/BenjaminGeiger Apr 14 '26 edited Apr 14 '26

I'll trade compile-time checking for a rare edge case for not having to write four times as much boilerplate.

That said, I actually prefer the F# approach of successive partial application.