Computer Science, asked by rachnahrd3172, 1 year ago

Difference between overloaded functions and generic function

Answers

Answered by CBSEMP
8
For example, say you have a CalculatePay method on an Employee object. You may want to have one function signature that takes no parameters and uses the current date as the "as of" date. You may want a second function signature that takes a date. You may want a third function signature that takes two dates (start date and end date for the pay period).

Using generics, you may have a CheckForDuplicate method that takes any type of object (Employee, Customer, Lab Result, etc) and compares it against a passed in list. Maybe not the best example, but best I can do for a sunday morning. :-)

Hope this helps.
Answered by sumanrudra22843
0

Explanation:

The short answer is that method overloading is for passing different sets of data to a function. Generics are for passing different types to a function. ... You may want to have one function signature that takes no parameters and uses the current date as the "as of" date.

Similar questions