zoukankan      html  css  js  c++  java
  • 委托的理解

    using System;
    using System.Collections.Generic;
    using System.Collections;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;


    namespace ConsoleApplication1
    {

    class Program
    {
    //项目经理给出要求让几个程序员完成以下功能:
    //将两个字符串联合为一个,提供给自己调用
    delegate string methodDelegate(string s1,string s2);
    static void Main(string[] args)
    {
    //项目经理调用程序员A写的方法
    //声明:我要调用其他人写的代理(委托)方法
    methodDelegate delA = new methodDelegate(new ChengxuyuanA().ConnStrA);
    //输出
    Console.WriteLine(delA("123","456"));

    //项目经理也可以调用程序员B写的方法
    methodDelegate delB = new methodDelegate(new ChengxuyuanB().ConnStrB);
    Console.WriteLine(delB("123","456"));

    Console.ReadKey();
    }
    }


    //程序员A开始写的类以及实现方法
    public class ChengxuyuanA
    {
    //方法
    public string ConnStrA(string s1, string s2)
    {
    return s1 + s2;
    }
    }
    //程序员B写的类和方法
    public class ChengxuyuanB
    {
    //方法实现可不一样
    public string ConnStrB(String str1,string str2)
    {
    return str1 + str2;
    }
    }

    }

  • 相关阅读:
    Lookup注解
    解决数据量大,分页查询慢的方案
    一个http的请求分析
    MYSQL
    什么是性能优化
    编码规范随笔
    装饰者模式
    单例模式
    J.U.C并发包(1)
    Java内存模型
  • 原文地址:https://www.cnblogs.com/cnshuji/p/5441683.html
Copyright © 2011-2022 走看看