Method Overloading?

Method overloading, which allows you to create more than one method with the same name,but with a different set of parameters. When you call the method ,the CLR automatically choose the correct version by examining the parameters you supply.
This technique allows you to collect different versions of several methods together. For example, you might allow a database search that returns an array of Product object representing records in the database.Rather than create three methods with different names depending on the criteria,suchasGetProducts(),
GetProductsInCategory(),and GetActiveProducts(),you could create three versions of the GetProducts() methods. Each method would have the same name but a different signature ,meaning it would require different parameters.This example provides two overloaded versions for the GetProductPrice() method:

private decimal GetProductPrice(int ID)
{
// Code here
}
private decimal GetProductPrice(string name)
{
// Code here
}

No comments:

Post a Comment