"protected" methods in C#?

Sherif picture Sherif · May 30, 2009 · Viewed 28.1k times · Source

What are the benefits to defining methods as protected in C#?

like :

protected void KeyDemo_KeyPress( object sender, KeyPressEventArgs e ) 
{
    // some code
}

As compared to something like this:

private void FormName_Click( object sender, EventArgs e )
{
    //some code
}

I've seen such examples in many books and I don't understand why and when do they use private vs protected?

Answer

Philippe Leybaert picture Philippe Leybaert · May 30, 2009

Protected methods can be called from derived classes. Private methods can't.

That's the one and only difference between private and protected methods.