C
C#2y ago
MR1R0B0T

✅ When will we use overload method?

Hello. I would like to ask when do we have to use an overload method? I can't understand despite searching through different platforms for explanation.
8 Replies
Anton
Anton2y ago
E.g. the Where Linq method has two overloads One that takes a delegate that takes just the item And the second one that takes the item and the index arr.Where(item => item != 5)
MR1R0B0T
MR1R0B0TOP2y ago
Also it makes me confused because whenever I look at it they could have the same method invocation name yet they take different parameters so I was wondering instead of overloading that specific method, why not just declare another method?
Anton
Anton2y ago
vs arr.Where((item, index) => item != 5 && index != 8) it's less mental overload you just call the same method, you don't think about types it's called "static polymorphism"
MR1R0B0T
MR1R0B0TOP2y ago
Ahh, I see where you're getting at. Thank you for this explanation. I can already see it. Thank you!
Anton
Anton2y ago
and it generalizes better to generics or dynamic polymorphism
MR1R0B0T
MR1R0B0TOP2y ago
Thank you!
Anton
Anton2y ago
you're welcome
MR1R0B0T
MR1R0B0TOP2y ago
Have a great day ahead
Want results from more Discord servers?
Add your server