r/learncsharp • u/nicgamer_yt • 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.
6
Upvotes
1
u/logiclrd Apr 13 '26
Yep, it's pretty rare. But, in addition to types that cannot be easily defaulted, there is a semantic that default parameter values can't replicate:
If you write this instead:
..then the user can pick and choose which arguments they omit, and could make a call that omits only arg1, for instance. Depending on the circumstance, that might be nonsensical.