Some examples about how to write anonymous method and lambda expression
2011-10-31 14:13
519 查看
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace LandmaExpressionDemo { class Program { static void Main(string[] args) { //anonymous method Action ac = delegate() { Console.WriteLine("hello delegate"); }; ac(); //Use Action<T> to create anonymous method with parameters Action<string> ac2 = delegate(string strMessage) { Console.WriteLine(strMessage); }; ac2("hello world2"); //Pass the anonymous method to another method as parameter ActionHelper(delegate(string strMessage) { Console.WriteLine(strMessage); }); //use landmar expression as parameter to another method ActionHelper(fw => Console.WriteLine(fw)); //Use lambda expression as a delegate Action ac3 = () => Console.WriteLine("hello ac3"); ac3(); } public delegate void DisplayMessageDelegate(string strMesssage); public static void ActionHelper(Action<string> ac) { ac("hello world3"); } //Useful references //1. http://msdn.microsoft.com/en-us/library/018hxwa8.aspx //2. http://msdn.microsoft.com/en-us/library/bb549151.aspx //3. http://msdn.microsoft.com/en-us/library/bb397687.aspx //4. http://msdn.microsoft.com/en-us/library/bb534960.aspx } }
相关文章推荐
- About:How to write the declaration of pointers and references rightly.
- some materials about how to write technical articles
- Some thing about Lambda Expression and NHB
- about study method - how to learn faster and efficiency
- LINQ to Entities does not recognize the method , and this method cannot be translated into a store expression 解决办法
- some points to be think about how to create your
- How to mount partition with ntfs file system and read write access
- [原创]深入理解C# 3.x的新特性(3):从Delegate、Anonymous Method到Lambda Expression
- Talk about how to write good C# code from a bug
- How to Write and Publish a Scientific Paper: 7th Edition(科技论文写作与发表教程)
- define a class for a linked list and write a method to delete the nth node.
- Export/Import DataPump Parameter ACCESS_METHOD - How to Enforce a Method of Loading and Unloading Data ? [ID 552424.1]
- This program is used to explain how PCA works and the idea behind the method.
- [How to][Decompile and Recompile apks easily]{APKMULTITOOL METHOD}
- How to get FlexPaper’s Instance and some methods can we called
- How to use boost::property_tree to load and write JSON
- How to get Expression Encoder to work with the latest Apple QuickTime (7.64.17.0 and greater)
- How to invoke the method of managed bean and render view in JSF when we are outside the lifecycle of JSF
- whatever how, this should be record and be researched later. ---- about how to enable gpio value set in mach_smdk6410.c
- Some tips about how to reverse Array with C#