namespace DelegatesCS
{
using System;
public class Wisdom //包含代理的類
{
public delegate string GiveAdvice();
public string OfferAdvice(GiveAdvice Words)
{
return Words();
}
}
public class Parent //基類
{
public virtual string Advice()
{
return("Listen to reason");
}
~Parent() {}
}
public class Dad: Parent //子類
{
public Dad() {}
public override string Advice()
{
return("Listen to your Mom");
}
~Dad() {}
}
public class Mom: Parent //子類
{
public Mom() {}
public override string Advice()
{
return("Listen to your Dad");