当前位置:网站首页>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); 是匿名方法的主体.
委托可以通过匿名方法调用,也可以通过命名方法调用,即,通过向委托对象传递方法参数.
注意: 匿名方法的主体后面需要一个 ;.
例如:
实例
下面的实例演示了匿名方法的概念:
实例
当上面的代码被编译和执行时,它会产生下列结果:
边栏推荐
- Realize serial port receiving data based on STM32 ring queue
- 高效并发:Synchornized的锁优化详解
- Bionic caterpillar robot source code
- 【Yugong Series】July 2022 Go Teaching Course 025-Recursive Function
- [Intensive reading of the paper] iNeRF
- Summary of the classic drawing method of histogram
- TestCafeSummary
- Student management system on the first day: complete login PyQt5 + MySQL5.8 exit the operation logic
- focus on!Haitai Fangyuan joins the "Personal Information Protection Self-discipline Convention"
- ReentrantLock原理(未完待续)
猜你喜欢
The old music player WinAmp released version 5.9 RC1: migrated to VS 2019, completely rebuilt, compatible with Win11
ReentrantLock原理(未完待续)
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"
AI automatic code writing plugin Copilot (co-pilot)
STM32 full series development firmware installation guide under Arduino framework
Apache EventMesh distributed event-driven multi-runtime
高效并发:Synchornized的锁优化详解
Implementation of a sequence table
Write a database document management tool based on WPF repeating the wheel (1)
Financial profitability and solvency indicators
随机推荐
The article you worked so hard to write may not be your original
Apache EventMesh distributed event-driven multi-runtime
Teach you how to deploy Nestjs projects
UserAgent resolution
GAC Honda Safety Experience Camp: "Danger" is the best teacher
Qualcomm cDSP simple programming example (to query Qualcomm cDSP usage, signature), RK3588 npu usage query
返回一个零长度的数组或者空的集合,不要返回null
Unity-通过预制件和克隆方法动态实现各个UGUI下控件的创建和显示
-xms -xmx(information value)
Batch (batch size, full batch, mini batch, online learning), iterations and epochs in deep learning
[Code Hoof Set Novice Village 600 Questions] Merge two numbers without passing a character array
Audio alignment using cross-correlation
登录业务实现(单点登录+微信扫码+短信服务)
Poker Game in C# -- Introduction and Code Implementation of Blackjack Rules
支付模块实现
Basic Grammar Introduction of Carbon Tutorial (Tutorial)
grep命令 笔试题
Istio introduction
grep command written test questions
【AcWing】The 62nd Weekly Match 【2022.07.30】