无法通过引用返回范围变量
以下示例生成 CS8159:
// CS8159.cs (7,74)
using System.Linq;
class TestClass
{
delegate ref char RefCharDelegate();
void TestMethod()
{
var x = from c in "TestValue" select (RefCharDelegate)(() => ref c);
}
}
若要返回范围变量,请重构为按值返回以更正此错误:
using System.Linq;
class TestClass
{
delegate char RefCharDelegate();
void TestMethod()
{
var x = from c in "TestValue" select (RefCharDelegate)(() => c);
}
}