在已有类中定义事件,为事件指定方法(虚方法A),子类中重写虚方法(重写方法A)B,那么在事件出发时,调用的是方法B。
public class
ClsBase
{
public delegate void BaseMethod(string
baseparam);
public event BaseMethod
ItemDeleting;
public
ClsBase()
{
ItemDeleting +=
new BaseMethod
(ClsBase_ItemDeleting);
ItemDeleting(
@"D:/foll/Test.txt"
);
}
protected virtual void ClsBase_ItemDeleting(string
baseparam)
{
if (File
.Exists(baseparam))
{
File
.Delete(baseparam);
}
}
}
public class ClsTest :
ClsBase
{
protected override void ClsBase_ItemDeleting(string
baseparam)
{
if (System.Windows.Forms.MessageBox.Show("Do you want to delete!"
,
"Demo", System.Windows.Forms.MessageBoxButtons.OKCancel) == System.Windows.Forms.DialogResult
.OK)
{
base
.ClsBase_ItemDeleting(baseparam);