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,也就是最后一个监听的返回值。

相关推荐
用户7884773163415 小时前
WinForms 迁移 WPF:Upgrade Assistant 覆盖 30%,剩下 70% 我手写了六周
c#
寂寞的船20 小时前
【Unity知识速递】第13期 Unity 内存泄漏排查实战:从 Memory Profiler 到 Lua 引用泄漏的生产级全链路诊断
unity·junit·c#·游戏引擎·lua
用户3721574261352 天前
C# 提取 PDF 附件:包括文档附件和页面注释附件
c#
寂寞的船2 天前
【Unity Bug挑战】第12期 Awaitable 二次 await 死锁之谜 —— 为什么同一个异步操作等两次就卡死?
unity·c#·游戏引擎·bug
浪浪山_大橙子2 天前
被1.4 MB的射击游戏震撼后,我认真拆了一遍Fable的实现
ai编程·游戏开发·three.js
SmalBox2 天前
10-02-实战-Unity原生AssetBundle实战
unity3d·游戏开发
探求虚无3 天前
用 AI 在 Unity 里做一款 RTS:最难的不是生成代码,而是证明它真的能玩
人工智能·unity·游戏引擎
SmalBox3 天前
10-01-实战-环境搭建与集成
unity3d·游戏开发
huaqianzkh3 天前
WinForm C#:循环修改控件UI闪烁卡顿?SuspendLayout / ResumeLayout 与 BeginUpdate 优化
开发语言·ui·c#
SmalBox3 天前
09-04-生态-UOS CDN与服务器部署
unity3d·游戏开发