前文:
這個文章和大家分享解說 Func<>和Action<>
最後帶著大家來實現自己的Linq Where
先來看 Func<> ,Action<>
原始定義
我們發現Func<> ,Action<>
其實本質就是委託 ,雖然有十幾個重載 但大同小異
public delegate TResult Func<out TResult>();
public delegate void Action<in T>(T obj);
Func
固定最後一個泛型參數為方法回傳值,其餘是傳入參數
public delegate TResult Func<in T, out TResult>(T arg);
解說Func:
宣告一個Func<Person,string>
委託 _thunkCheckAge
_thunkCheckAge
委託指向CheckAge
方法
執行_thunkCheckAge
委託 (執行CheckAge
方法)