当前位置:网站首页>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); 是匿名方法的主体.
委托可以通过匿名方法调用,也可以通过命名方法调用,即,通过向委托对象传递方法参数.
注意: 匿名方法的主体后面需要一个 ;.
例如:
实例
下面的实例演示了匿名方法的概念:
实例
当上面的代码被编译和执行时,它会产生下列结果:
边栏推荐
- multithreaded lock
- 第六章
- 财务盈利、偿债能力指标
- Implementing a Simple Framework for Managing Object Information Using Reflection
- Short-circuit characteristics and protection of SiC MOSFETs
- Talking about the algorithm security of network security
- [PIMF] OpenHarmony Thesis Club - Inventory of the open source Hongmeng tripartite library [3]
- Qualcomm cDSP simple programming example (to query Qualcomm cDSP usage, signature), RK3588 npu usage query
- The whole network is on the verge of triggering, and the all-round assistant for content distribution from media people - Rongmeibao
- cas and spin locks (is lightweight locks spin locks)
猜你喜欢

Poker Game in C# -- Introduction and Code Implementation of Blackjack Rules

The old music player WinAmp released version 5.9 RC1: migrated to VS 2019, completely rebuilt, compatible with Win11

Flink_CDC construction and simple use

Memblaze released the first enterprise-grade SSD based on long-lasting particles. What is the new value behind it?

IDA PRO中汇编结构体识别

The principle of ReentrantLock (to be continued)

Embedded development has no passion, is it normal?
![leetcode: 6135. The longest ring in the graph [inward base ring tree + longest ring board + timestamp]](/img/91/284de3dcbb8d143d85775b314dd41c.png)
leetcode: 6135. The longest ring in the graph [inward base ring tree + longest ring board + timestamp]

全网一触即发,自媒体人的内容分发全能助手——融媒宝

TestCafeSummary
随机推荐
C#中引用类型的变量做为参数在方法调用时加不加 ref 关键字的不同之处
AI 自动写代码插件 Copilot(副驾驶员)
Realization of character makeup
Flink_CDC construction and simple use
返回一个零长度的数组或者空的集合,不要返回null
【论文精读】iNeRF
Architect 04 - Application Service Encryption Design and Practice
[PIMF] OpenHarmony Thesis Club - Inventory of the open source Hongmeng tripartite library [3]
统计UTF-8字符串中的字符函数
Socket回顾与I/0模型
Apache EventMesh distributed event-driven multi-runtime
NVIDIA已经开始测试AD106和AD107 GPU核心的显卡产品
Golang - from entry to abandonment
spark reports an error OutOfMemory "recommended collection"
BM3 flips the nodes in the linked list in groups of k
leetcode: 6135. The longest ring in the graph [inward base ring tree + longest ring board + timestamp]
UVM RAL model and built-in seq
linux查看redis版本命令(linux查看mysql版本号)
Go mode tidy reports an error go warning “all” matched no packages
[Intensive reading of the paper] iNeRF