当前位置:网站首页>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); 是匿名方法的主体.
委托可以通过匿名方法调用,也可以通过命名方法调用,即,通过向委托对象传递方法参数.
注意: 匿名方法的主体后面需要一个 ;.
例如:
实例
下面的实例演示了匿名方法的概念:
实例
当上面的代码被编译和执行时,它会产生下列结果:
边栏推荐
- Bionic caterpillar robot source code
- Count characters in UTF-8 string function
- 基于STM32 环形队列来实现串口接收数据
- 支付模块实现
- What's wrong with the sql syntax in my sql
- pytorch lstm时间序列预测问题踩坑「建议收藏」
- 角色妆容的实现
- [Open class preview]: Research and application of super-resolution technology in the field of video image quality enhancement
- 二叉树非递归遍历
- "The core concept of" image classification and target detection in the positive and negative samples and understanding architecture
猜你喜欢
IDA PRO中汇编结构体识别
Basic configuration of OSPFv3
嵌入式开发没有激情了,正常吗?
关注!海泰方圆加入《个人信息保护自律公约》
GateWay implements load balancing
NVIDIA已经开始测试AD106和AD107 GPU核心的显卡产品
Collation of knowledge points in Ningbo University NBU IT project management final exam
leetcode: 6135. The longest ring in the graph [inward base ring tree + longest ring board + timestamp]
Quick Start Tutorial for flyway
21. Support Vector Machine - Introduction to Kernel Functions
随机推荐
C#中引用类型的变量做为参数在方法调用时加不加 ref 关键字的不同之处
一款国外开发的高质量WordPress下载站模板主题
Count characters in UTF-8 string function
UVM RAL model and built-in seq
Linux environment redis cluster to build "recommended collection"
AI automatic code writing plugin Copilot (co-pilot)
BM5 合并k个已排序的链表
Chapter VII
Redis综述篇:与面试官彻夜长谈Redis缓存、持久化、淘汰机制、哨兵、集群底层原理!...
求n以内的素数
JS basic exercises
The principle of ReentrantLock (to be continued)
The old music player WinAmp released version 5.9 RC1: migrated to VS 2019, completely rebuilt, compatible with Win11
【核心概念】图像分类和目标检测中的正负样本划分以及架构理解
【论文精读】iNeRF
角色妆容的实现
Audio alignment using cross-correlation
Commonly used security penetration testing tools (penetration testing tools)
ThreadLocal
uniapp小程序检查、提示更新