当前位置:网站首页>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); 是匿名方法的主体.
委托可以通过匿名方法调用,也可以通过命名方法调用,即,通过向委托对象传递方法参数.
注意: 匿名方法的主体后面需要一个 ;.
例如:
实例
下面的实例演示了匿名方法的概念:
实例
当上面的代码被编译和执行时,它会产生下列结果:
边栏推荐
- GAC Honda Safety Experience Camp: "Danger" is the best teacher
- STM32 full series development firmware installation guide under Arduino framework
- Collation of knowledge points in Ningbo University NBU IT project management final exam
- uniapp小程序检查、提示更新
- 每月一书(202207):《Swift编程权威指南》
- BM5 合并k个已排序的链表
- Realize serial port receiving data based on STM32 ring queue
- flowable workflow all business concepts
- Daily practice——Randomly generate an integer between 1-100 and see how many times you can guess.Requirements: The number of guesses cannot exceed 7 times, and after each guess, it will prompt "bigger"
- Returns a zero-length array or empty collection, do not return null
猜你喜欢

Efficient Concurrency: A Detailed Explanation of Synchornized's Lock Optimization

顺序表的实现

The article you worked so hard to write may not be your original

The principle of ReentrantLock (to be continued)

利用反射实现一个管理对象信息的简单框架

Go mode tidy reports an error go warning “all” matched no packages

Bika LIMS open source LIMS set - use of SENAITE (detection process)
![[Code Hoof Set Novice Village 600 Questions] Merge two numbers without passing a character array](/img/4d/038e6cd6ecad19934122cff89f4d76.png)
[Code Hoof Set Novice Village 600 Questions] Merge two numbers without passing a character array

NVIDIA has begun testing graphics products with AD106 and AD107 GPU cores

IDA PRO中汇编结构体识别
随机推荐
renderjs usage in uni-app
Realization of character makeup
Batch (batch size, full batch, mini batch, online learning), iterations and epochs in deep learning
支付模块实现
Structure of the actual combat battalion module eight operations
BM5 merge k sorted linked lists
Several methods for deleting specified elements in Golang slices
UVM RAL model and built-in seq
IDA PRO中汇编结构体识别
Arduino框架下STM32全系列开发固件安装指南
Daily practice——Randomly generate an integer between 1-100 and see how many times you can guess.Requirements: The number of guesses cannot exceed 7 times, and after each guess, it will prompt "bigger"
grep命令 笔试题
架构实战营模块 8 作业
NVIDIA已经开始测试AD106和AD107 GPU核心的显卡产品
[Open class preview]: Research and application of super-resolution technology in the field of video image quality enhancement
Commonly used security penetration testing tools (penetration testing tools)
GAC Honda Safety Experience Camp: "Danger" is the best teacher
Go mode tidy reports an error go warning “all” matched no packages
Chapter VII
VOT2021比赛简介