防止Lambda的各种坑爹(一)
2012-12-02 14:25
183 查看
1.奇怪的被捕获的变量:
View Code
OK,我想你现在明白了,"局部变量“不一定是局部的了吧。
View Code
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace TestLambda { class Program { static void Main(string[] args) { Action action = CreateAction(); action(); action(); action(); var a = DynamicCreateAction(); a(); a(); a(); Console.Read(); } static Action CreateAction() { int value = 0; Action action = () => Console.Write(value++); return action; } static Action DynamicCreateAction() { DisplayClass d = new DisplayClass(); Action action = new Action(d.Print); return action; } class DisplayClass { public int Value { get; set; } public void Print() { Console.Write(Value++); } } } }
OK,我想你现在明白了,"局部变量“不一定是局部的了吧。
相关文章推荐
- Yui.Compressor高性能ASP.NET开发:自动压缩CSS、JS防止Lambda的各种坑爹(一)
- 防止Lambda的各种坑爹(二)
- struts_05 各种验证器,ognl表达式,struts2常用标签,防止表单重复提交,jfreeChart插件的运用
- 弹性布局各种坑爹兼容
- c#系列之各种lambda表达式
- Android Studio各种坑爹之:finished with non-zero exit value 1和Return code 1 for dex process.
- Android Studio各种坑爹之:Error running app: Instant Run requires 'Tools | Android | Enable ADB integratio
- ADC0832的C程序(我怎么感觉网上的各种坑爹,还是自己YY了一个)
- 各种坑爹小问题,大麻烦(持续更新)
- 弹性布局各种坑爹兼容
- 一篇文章普及各种ios基本知识(防止奸商忽悠、鉴别假冒翻新机、知识入门必备)
- Android Studio各种坑爹之:dalvikvm: Could not find class 'android.util.ArrayMap'
- 鉴于开源博客服务器各种坑爹,不再这里做笔记了.
- 浏览器各种坑爹兼容问题
- WinForm 防止因为各种因素的操作导致主窗体冻结、卡死的解决方法
- 防止提交 AppStore 各种事故的发生
- Python中匿名函数lambda的各种用法
- IOS的各种控件(转载,防止遗忘)
- Eclipse中各种文件【默认编码格式设置】,防止乱码等问题
- 开发中遇到的各种坑爹错误及修改