What is the difference between overloading and overriding?

Technology CommunityCategory: C#What is the difference between overloading and overriding?
VietMX Staff asked 3 years ago
  • Overloading is when you have multiple methods in the same scope, with the same name but different signatures.
//Overloading
public class test
{
    public void getStuff(int id)
    {}
    public void getStuff(string name)
    {}
}
  • Overriding is a principle that allows you to change the functionality of a method in a child class.
//Overriding
public class test
{
        public virtual void getStuff(int id)
        {
            //Get stuff default location
        }
}

public class test2 : test
{
        public override void getStuff(int id)
        {
            //base.getStuff(id);
            //or - Get stuff new location
        }
}