当前位置:网站首页>Learn about C# anonymous methods
Learn about C# anonymous methods
2022-07-31 22:07:00 【51CTO】
委托是用于引用与其具有相同标签的方法.换句话说,可以使用委托对象调用可由委托引用的方法. |
匿名方法(Anonymous methods) 提供了一种传递代码块作为委托参数的技术.匿名方法是没有名称只有主体的方法.
在匿名方法中您不需要指定返回类型,它是从方法主体内的 return 语句推断的.
编写匿名方法的语法
匿名方法是通过使用 delegate 关键字创建委托实例来声明的.例如:
代码块 Console.WriteLine("Anonymous Method: {0}", x); 是匿名方法的主体.
委托可以通过匿名方法调用,也可以通过命名方法调用,即,通过向委托对象传递方法参数.
注意: 匿名方法的主体后面需要一个 ;.
例如:
实例
下面的实例演示了匿名方法的概念:
实例
当上面的代码被编译和执行时,它会产生下列结果:
边栏推荐
- leetcode: 6135. The longest ring in the graph [inward base ring tree + longest ring board + timestamp]
- Introduction to Audio Types and Encoding Formats in Unity
- 每月一书(202207):《Swift编程权威指南》
- Unity-通过预制件和克隆方法动态实现各个UGUI下控件的创建和显示
- c语言解析json字符串(json对象转化为字符串)
- HTC使用官方固件作为底包制作rom卡刷包教程
- BM5 merge k sorted linked lists
- How to debug TestCafe
- ReentrantLock原理(未完待续)
- Niuke.com brush questions (1)
猜你喜欢
Federated Learning: Multi-source Knowledge Graph Embedding in Federated Scenarios
flowable workflow all business concepts
Implementing a Simple Framework for Managing Object Information Using Reflection
统计UTF-8字符串中的字符函数
【公开课预告】:超分辨率技术在视频画质增强领域的研究与应用
财务盈利、偿债能力指标
Flex layout in detail
Write a database document management tool based on WPF repeating the wheel (1)
NVIDIA has begun testing graphics products with AD106 and AD107 GPU cores
Go1.18 upgrade function - Fuzz test from scratch in Go language
随机推荐
Several methods of mysql backup table
【AcWing】The 62nd Weekly Match 【2022.07.30】
Go mode tidy reports an error go warning “all” matched no packages
嵌入式开发没有激情了,正常吗?
Embedded development has no passion, is it normal?
全网一触即发,自媒体人的内容分发全能助手——融媒宝
Federated Learning: Multi-source Knowledge Graph Embedding in Federated Scenarios
[Code Hoof Set Novice Village 600 Questions] Merge two numbers without passing a character array
sqlite3简单操作
[Code Hoof Set Novice Village 600 Questions] Leading to the combination of formulas and programs
rj45 to the connector Gigabit (Fast Ethernet interface definition)
Structure of the actual combat battalion module eight operations
idea中搜索具体的字符内容的快捷方式
IDA PRO中汇编结构体识别
【AcWing】The 62nd Weekly Match 【2022.07.30】
[Intensive reading of the paper] iNeRF
"The core concept of" image classification and target detection in the positive and negative samples and understanding architecture
高通cDSP简单编程例子(实现查询高通cDSP使用率、签名),RK3588 npu使用率查询
Linux environment redis cluster to build "recommended collection"
ReentrantLock原理(未完待续)