Overloading is the process of defining a number of methods with the same name and return type, but which has different parameters. For example, you might want a method that returns the file content based on the string path:
public string GetFileContent(string path)
{
return File.ReadAllText(path);
}
But you might also find it helpful to define a method which uses a FileInfo:
public string GetFileContent(FileInfo fi)
{
return GetFileContent(fi.FullName);
}
GetFileContent
is an overloaded method - it has different versions and which is called depends on teh paramatyers you supply. In the Bad Old Days we would have had to define two differently named methods:
GetFileContentFromPath
GetFileContentFromFileInformation
And then try to remember which were available, and took what parameters!
Overriding is more complex: it is the process of creating a method that sits on top of an existing method in a base class, and which will be called instead of the base class method when it it called. This allows you to have two different derived classes, which both override the same base class method to do class specific actions. When you call the method on an object derived from the base class, the framework works out which method it should call, and class the "highest" override in the list.
You have probably used this quite a bit without noticing it: ToString is very often overridden to provide a human readable version of the class. The default
object
definition of ToString prints the class name, but when it it overridden it prints the content.