【读书笔记】Lambda表达式
生活随笔
收集整理的這篇文章主要介紹了
【读书笔记】Lambda表达式
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
??? Lambda表達式,是一個匿名函數,它可以包含表達式和語句,并且可用于創建委托或表達式目錄樹類型。
??? Lambda表達式, 都是用"=>"運算符。 讀作"goes to"。Lambda表達式運算符的左邊是輸入參數(如果有),右邊包含表達式或語句塊。使用格式如下:
(input parameters) => expression;
“Lambda表達式”是委托的實現方法,所以必須遵循以下規則: -
1)“Lambda表達式”的參數數量必須和“委托”的參數數量相同; -
2)如果“委托”的參數中包括有ref或out修飾符,則“Lambda表達式”的參數列中也必須包括有修飾符
大家都知道,一個類的私有成員只能在他的內部訪問! using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace Lambda
{delegate bool D();delegate bool D2(int i);class Test{public D del;public D2 del2;public void TestMethod(int input){int j = 0;del = () => {j = 10;return j > input;};del2 = (x) =>{return x == j;};Console.WriteLine("j = {0}", j);bool boolResult = del();Console.WriteLine("j = {0}, b = {1}", j, boolResult); }}class Program{static void Main(string[] args){Test test = new Test();test.TestMethod(5); bool result = test.del2(10);Console.WriteLine(result);Console.ReadKey();}}
}私有成員,在類外面不能引用. private int x; Cla cla = new Cla() cla.x 這樣引用是錯的 ? 如果public int x; Cla cla = new Cla()
cla.x 這樣引用是對的
You can also create an anonymous method using an operator called lambda and represented by =>. From our example above, to use the lambda operator to create an anonymous method, omit the delegate keyword and follow the parentheses by the operator. Here is an example:
轉載于:https://www.cnblogs.com/herbert/archive/2010/03/22/1691766.html
總結
以上是生活随笔為你收集整理的【读书笔记】Lambda表达式的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [JS,CSS] - CSS圆角框组件
- 下一篇: 终焉誓约符文怎么获得?