什么是结束?我们在.NET有他们吗?
如果它们确实存在于.NET中,您能提供一个代码片段(最好是在C#中)来解释它吗?
发布于 2016-08-16 15:26:41
闭包是指在另一个函数(或方法)中定义一个函数,并使用父方法中的变量。这种使用位于方法中并包装在其中定义的函数中的变量称为闭包。
Mark在他的博客文章中有一些有趣的闭包示例,他在oop和函数式编程之间做了一个副词。
让它更详细
var workingDirectory = new DirectoryInfo(Environment.CurrentDirectory);//when this variable
Func<int, string> read = id =>
{
var path = Path.Combine(workingDirectory.FullName, id + ".txt");//is used inside this function
return File.ReadAllText(path);
};//the entire process is called a closure.https://stackoverflow.com/questions/428617
复制相似问题