3.3 Method-Overloading
Objectives
Discussion
File Location
Example
class Player
{
// 1
public void Attack()
{
Console.WriteLine("The player attacked for 5 points");
}
// 2
public void Attack(int attackPoints)
{
Console.WriteLine("The player attacked for {0} points and has the sword", attackPoints);
}
// 3
public void Attack(int attackPoints, string weaponName)
{
Console.WriteLine("The player attacked for {0} points and has a {1}", attackPoints, weaponName);
}
}One More Example
Discussion
Challenge
Last updated