为什么out参数不是一个匿名方法允许范围内? [英] Why is an out parameter not allowed within an anonymous method?

查看:127
本文介绍了为什么out参数不是一个匿名方法允许范围内?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是没有的从匿名方法调用带有ref或out参数的方法

我想知道的为什么出参数不允许匿名内方法。不允许 REF 参数,使更多的意义,我,但在退出参数,没有那么多。

I am wondering why out parameters are not allowed within anonymous methods. Not allowing ref parameters makes a bit more sense to me, but the out parameters, not as much.

什么是您对这个

推荐答案

在某些方面想法此是一种欺骗。 退出参数 REF 参数。根本就上所使用的C#语言值的额外属性。之所以不允许他们是完全相同的 REF 参数。

In some ways this is a dupe. Out parameters are ref parameters. There is simply an extra attribute on the value that is used by the C# language. The reason for disallowing them is the exact same as ref parameters.

这里的问题,使用的效果起源匿名方法中的匿名方法外部声明的价值。这样做将捕捉到的lambda内不得已的任意值,其使用寿命超出当前的功能。这是不是出于具有固定的寿命参数与兼容。

The problem here originates with the effect of using a value declared outside the anonymous method within the anonymous method. Doing so will capture the value within the lambda and out of necessity arbitrarily extend its lifetime beyond that of the current function. This is not compatible with out parameters which have a fixed lifetime.

想象一下,例如,该出所指的堆栈中的局部变量参数。在lambda可以在未来任意点执行,因此当栈帧不再有效可以执行。你会在退出参数,然后呢?

Imagine for instance that the out parameter referred to a local variable on the stack. The lambda can execute at any arbitrary point in the future and hence could execute when that stack frame was no longer valid. What would the out parameter mean then?

这篇关于为什么out参数不是一个匿名方法允许范围内?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆