【问题标题】:What does this "Lambda Expression" do?这个“Lambda 表达式”有什么作用?
【发布时间】:2011-05-17 09:18:35
【问题描述】:
刚刚遇到以下代码行并且很难找到它的文档,它是lambda expression吗?这是做什么的?
temp = Regex.Replace(url, REGEX_COOKIE_REPLACE,match => cookie.Values[match.Groups["CookieVar"].Value]);
对=>特别感兴趣。
【问题讨论】:
标签:
c#
.net
c#-4.0
matchevaluator
【解决方案2】:
match => cookie.Values[match.Groups["CookieVar"].Value]
是一个快捷方式
delegate (Match match)
{
return cookie.Values[match.Groups["CookieVar"].Value];
}
【解决方案3】:
RegEx.Replace 为 url 中的每个 REGEX_COOKIE_REPLACE 匹配运行 lambda,并用 lambda 结果“替换”匹配。
lambda(或速记委托)
match => cookie.Values[match.Groups["CookieVar"].Value]
使用Match,的“CookieVar”Group,的Value在cookie.Values集合中查找替换。查找值替换匹配项。
要告诉您有关“CookieVar”组的更多信息,我们需要查看REGEX_COOKIE_REPLACE. 的评估