有人可以請幫忙解釋下面的代碼中發生了什麼?非常感謝!結果是meo,但我不明白這兩個'在哪裏'在這種情況下工作。C#在哪裏,並選擇
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;
第二個where子句不會讓當前的'Cat'通過,是嗎? – displayName
謝謝!我有點困惑。是哪裏的擴展方法在哪裏?爲什麼在使用(小寫字母)的表達式中,在何處查看錶達式? – user3735871
'Where'是類Cat中定義的自定義方法。它不是.NET框架中的Where方法。 –