当前位置:网站首页>Unity C# 基础复习27——委托示例(P448)
Unity C# 基础复习27——委托示例(P448)
2022-06-29 14:39:00 【_一只小QQ】
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Cook
{
public static String Step1()
{
Console.WriteLine("放油");
return null;
}
public static String Step2()
{
Console.WriteLine("放葱");
return null;
}
public static String Step3()
{
Console.WriteLine("放菜");
return null;
}
public static String Step4()
{
Console.WriteLine("放调料");
return null;
}
public static String Step5()
{
return "糖醋里脊";
}
}
}using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
delegate String Cooking();
class Program
{
static void Main(string[] args)
{
Cooking cook = Cook.Step1;
cook += Cook.Step2;
cook += Cook.Step3;
cook += Cook.Step4;
cook += Cook.Step5;
cook -= Cook.Step1;
String result = cook();
Console.WriteLine(result);
}
}
}

最后一个返回值的return 糖醋里脊。如果把cook+=Cook.Step5往前调整,则会打印出null
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
delegate String Cooking();
class Program
{
static void Main(string[] args)
{
Cooking cook = Cook.Step1;
cook += Cook.Step2;
cook += Cook.Step3;
cook += Cook.Step5;
cook += Cook.Step4;
String result = cook();
Console.WriteLine(result);
}
}
}
委托的流程带返回值的话永远是得到最后一个方法的返回值
边栏推荐
- [Verilog quick start of Niuke online question series] ~ shift operation and multiplication
- Practical application cases of drives
- Huali biology rushes to the scientific innovation board: the annual revenue is RMB 226million and it is planned to raise RMB 800million
- 异步神器CompletableFuture
- [shell] Jenkins shell realizes automatic deployment
- Differences between @resource and @autowired annotations automatically injected:
- Redis installation in windows and Linux Environment
- 仿头条新闻资讯dz模板 Discuz新闻资讯商业版GBK模板源码
- synchronized 与多线程的哪些关系
- VQA needs not only pictures, but also external knowledge! University of Washington & Microsoft proposed revive, using gpt-3 and wikidata to help answer questions
猜你喜欢

Paper study -- accurate accounting of annual total runoff control rate considering the interannual variation characteristics of rainfall

Huashu high tech rushes to the scientific innovation board: the actual controller xuxiaoshu and his son, who plan to raise 660million yuan, are both American nationals

Slow bear market, bit Store provides stable stacking products to help you cross the bull and bear

驱动器实际运用案例

Is 100W data table faster than 1000W data table query in MySQL?

华理生物冲刺科创板:年营收2.26亿 拟募资8亿

两个字的名字如何变成有空格的3个字符的名字

关于项目采购管理,这些你需要知道

Query function of Excel vlookup

阿尔兹海默病智能诊断
随机推荐
synchronized 与多线程的哪些关系
konva系列教程4:图形属性
[blackduck] configure the specified Synopsys detect scan version under Jenkins
China soft ice cream market forecast and investment prospect research report (2022 Edition)
Deploy redis sentry in k8s
《canvas》之第5章 文本操作
Heavyweight! The latest SCI impact factors were released in 2022, and the ranking of the three famous journals NCS and the top10 of domestic journals has changed (the latest impact factors in 2022 are
华曙高科冲刺科创板:拟募资6.6亿 实控人许小曙父子均为美国籍
I log in to the RDB database and prompt that the master account authorization is required. How do I know who to call?
关于项目采购管理,这些你需要知道
Class template case - array class encapsulation
校园跑腿微信小程序跑腿同学带直播新版源码
[shell] Jenkins shell realizes automatic deployment
Laravel - composer installs the specified laravel version
VQA needs not only pictures, but also external knowledge! University of Washington & Microsoft proposed revive, using gpt-3 and wikidata to help answer questions
Asynchronous artifact completable future
PostgreSql学习(基于菜鸟课程)
知乎热议:一个程序员的水平能差到什么程度?
go学习(四、面向接口)
云上第一课 | 建个小破站有多简单?云计算老司机带你一小时搞定