双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

求指点“委托,回调函数”的理解

xjw163 xjw163 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
学习知识,理解最重要

看到一篇解释回调函数的文章
http://blog.163.com/xiao_mege/blog/static/729427532011327430903/
中对委托做了这样一个比喻
“一天你老婆让你去市场买菜,而你因为偷懒就让你的儿子去买,把菜买回来了你直接将菜交给老婆.而老婆只是想要菜,并不关心菜是谁买的.第二天你老婆让你去买米,结果你又交由儿子处理.第三天老婆让去买肉,可怜的儿子再次被你叫去了... ”
根据这样的描述,有如下代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace test回调函数自己的理解
{
class Program
{
static void Main(string[] args)
{
Mother mother = new Mother();
Father father=new Father();
Son son = new Son();
string cookneed = mother.motherwant;
mother.motherget=father.fotherbuy(cookneed,son.sonbuy);
Console.WriteLine("mother get the "+ mother.motherget);
Console.ReadLine();
}
}

class Mother
{
public string motherwant="luobo";
public string motherget;
public void motherbuy(string materialwant)
{
}
}
class Father
{
public delegate string Buy(string meterie);
public string fotherbuy(string cookneed,Buy buy)
{
return buy(cookneed);
}
}
class Son
{
public string sonbuy(string material)
{
Console.WriteLine("son buy " + material);
return material;
}
}
}

求指点这样的理解是否正确?
...全文

相关推荐

评论 18
收藏 已收藏
分享
返回顶部
xjw163
C# 111,129 成员 642,540 内容