C#声明一个带返回值的委托

1、声明

public delegate string TestDel(string str);

2、使用

TestDel t;

t = (string str) => str;

t += (string str) => str + "1";

t += (string str) => str + "2";

t += (string str) => str + "3";

Console.WriteLine(t ("hhhh"));

3,总结

(这里添加监听使用了表达式Lambda,参考C#语法_匿名方法与Lambda表达式)

这里会打印hhhh3,也就是最后一个监听的返回值。

相关推荐
XiaoZhenHua9813 小时前
C# WinForms + 西门子S7 + SQLite + EPPlus生产数据采集系统架构设计
系统架构·sqlite·c#
Lost of 程序猿14 小时前
船岸数据同步链路实战:SendFlag、单调版本号与断网三天后的续传
后端·c#·asp.net
心前阳光1 天前
Unity发布PC软件图标不能改变
unity·游戏引擎
SmalBox1 天前
01-07-认知篇-对比-原生AssetBundle工作流
unity3d·游戏开发
an86950011 天前
unity如何在visual studio中打断点debug
unity·游戏引擎·visual studio
xcLeigh1 天前
Unity基础:使用Transform控制物体移动——Translate与position详解
unity·游戏引擎
cjp5601 天前
012.UG二次开发,UG管道服务器与WPF管道通讯,传输JSON数据
c#
FairGuard手游加固1 天前
Unity小游戏加密:global-metadata.dat与AssetBundle保护
游戏·unity·游戏引擎
jiushidt1 天前
ArcGIS Pro Add‑in 打包流程详解
arcgis·c#·.net·arcgispro
狂人开飞机1 天前
11、UI系统
游戏引擎·godot