✅ 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
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)
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?
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"Ahh, I see where you're getting at. Thank you for this explanation. I can already see it. Thank you!
and it generalizes better to generics or dynamic polymorphism
Thank you!
you're welcome
Have a great day ahead