天天看點

Lambda 表達式(C# 程式設計指南)

Lambda 表達式是一種可用于建立或類型的。通過使用 lambda

表達式,可以寫入可作為參數傳遞或作為函數調用值傳回的本地函數。  Lambda 表達式對于編寫 LINQ

查詢表達式特别有用。 

=>, and you put the expression or statement block on the other side.‘

data-guid="35d22bcb09811da5e0ec07f34c10c0a8">若要建立 Lambda 表達式,需要在 Lambda 運算符

左側指定輸入參數(如果有),然後在另一側輸入表達式或語句塊。x => x * x specifies a parameter that’s named x and returns the value of x squared.‘

data-guid="c072edd5f07566e3185446a6649f1fe0">例如,lambda 表達式 x

=> x * x 指定名為 x 的參數并傳回 x 的平方值。  如下面的示例所示,你可以将此表達式配置設定給委托類型:

語句Lambda