当前位置:编程学习 > JSP >>

一个有趣的例子:)关于delegate

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");
补充:Jsp教程,面向对象编程
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,