【发布时间】:2016-02-07 00:59:30
【问题描述】:
有人可以帮忙解释以下代码中发生了什么吗?非常感谢!结果是 meo,但我不明白这两个 'where' 在这种情况下是如何工作的。
public class Cat {
public string Text { get; set; }
public Cat Where(Func<Cat,bool> cond) {
return new Cat {
Text = cond(this)? this.Text.ToUpper(): this.Text.ToLower()
}; }
}
public static class CatExtensions {
public static T Select<T>(this Cat cat, Func<Cat,T> proj)
{
return proj(cat);
}
}
var moggy = new Cat { Text = "Meo" };
var result = from m in moggy
where true
where false
select m.Text;
【问题讨论】: