LINQ Lambda表达式Word下载.docx

上传人:b****8 文档编号:22862940 上传时间:2023-02-05 格式:DOCX 页数:13 大小:18.91KB
下载 相关 举报
LINQ Lambda表达式Word下载.docx_第1页
第1页 / 共13页
LINQ Lambda表达式Word下载.docx_第2页
第2页 / 共13页
LINQ Lambda表达式Word下载.docx_第3页
第3页 / 共13页
LINQ Lambda表达式Word下载.docx_第4页
第4页 / 共13页
LINQ Lambda表达式Word下载.docx_第5页
第5页 / 共13页
点击查看更多>>
下载资源
资源描述

LINQ Lambda表达式Word下载.docx

《LINQ Lambda表达式Word下载.docx》由会员分享,可在线阅读,更多相关《LINQ Lambda表达式Word下载.docx(13页珍藏版)》请在冰豆网上搜索。

LINQ Lambda表达式Word下载.docx

"

i"

is 

our 

parameter 

list.

0"

statement 

set 

to 

process 

.

应该这样来理解

My 

list 

of 

parameters 

(in 

this 

case 

single 

integer 

named 

will 

be 

processed 

by 

the 

expression 

0.

list.FindAll((i) 

((i 

0));

可以显式指定输入参数的类型

list.FindAll((int 

i) 

可以使用括号把输入参数和表达式括起来,如果参数或处理表达式只有一个,可以省略括号

有多行处理表达式时,需要使用花括号包起来

Console.WriteLine("

value 

currently:

{0}"

 

i);

bool 

isEven 

isEven;

当输入参数有多个时

SimpleMath 

new 

SimpleMath();

m.SetMathHandler((msg, 

result) 

{Console.WriteLine("

Message:

{0}, 

Result:

{1}"

msg, 

result);

或者显式指定输入参数类型

m.SetMathHandler((string 

int 

当没有输入参数时

VerySimpleDelegate 

VerySimpleDelegate( 

() 

{return 

Enjoy 

your 

string!

;

);

LINQLambda表达式实例

Postedon2008-02-1809:

56sunrack阅读(136)评论(0) 

Lambda表达式可以在使用代理和匿名代理的地方

1、命名函数

public 

class 

Common

delegate 

IntFilter(int 

static 

int[] 

FilterArrayOfInts(int[] 

ints, 

IntFilter 

filter)

ArrayList 

aList 

ArrayList();

foreach 

in 

ints)

if 

(filter(i))

aList.Add(i);

}

((int[])aList.ToArray(typeof(int)));

Application

IsOdd(int 

&

1) 

1);

using 

System.Collections;

nums 

1, 

2, 

3, 

4, 

5, 

6, 

7, 

8, 

9, 

10 

};

oddNums 

Common.FilterArrayOfInts(nums, 

Application.IsOdd);

oddNums)

Console.WriteLine(i);

2、匿名函数

=

delegate(int 

3、Lambda表达式

1));

三种方式的比较

method

anonymous 

i){return((i 

lambda 

expression

命名函数虽然简短,但是而外还要定义处理函数,优点是可以重用

学关于Lambda表达式的一二三

我是白痴,所以我不知道什么是lambda,看了网上N篇文章仍然还是个白痴。

还不知道。

于是。

给自己写篇自己能看得懂的文章,希望以后再白痴的时候看看就不白痴了。

委托

委托是一种引用方法的类型。

一旦为委托分配了方法,委托将与该方法具有完全相同的行为。

委托方法的使用可以像其他任何方法一样,具有参数和返回值。

漫画

委托就是给一个函数起一个别的名字。

System;

Declare 

-- 

defines 

required 

signature:

void 

SampleDelegate(string 

message);

MainClass

Regular 

method 

that 

matches 

SampleDelegateMethod(string 

message)

Console.WriteLine(message);

Main()

Instantiate 

with 

method:

SampleDelegate 

d1 

SampleDelegateMethod;

d2 

delegate(string 

d1("

Hello"

d2("

World,

这玩意也是委托

Form1()

InitializeComponent();

this.Click 

+= 

this.MultiHandler;

private 

MultiHandler(object 

sender, 

System.EventArgs 

e)

MessageBox.Show(((MouseEventArgs)e).Location.ToString());

匿名方法

匿名方法就是没名儿的委托。

虽然没名,但是必须加”delegate“来表示我没名。

Create 

instance

Del(int 

x);

an 

Del 

k) 

/* 

... 

*/ 

delegate() 

System.Console.WriteLine("

Copy 

#:

++n);

Printer(string 

s);

Printer 

j)

System.Console.WriteLine(j);

p("

The 

called."

string 

button1_Click(object 

EventArgs 

=delegate(string 

(j)+"

烦死了"

Console.WriteLine(p("

));

或者有名。

的匿名委托。

哈哈,我在抽风还是微软在抽风。

让我死吧。

Printer(Form1.DoWork);

DoWork(string 

k)

System.Console.WriteLine(k);

匿名方法就完了。

Lamdba就是(intx)=>

{x+1}就是这样的。

例子呢就是上面写了的一段用lambda就这样写

j+"

烦死了!

还能这么用

和上面那个一样,就是简化了。

(s, 

e) 

超难+===>

?

其实不难。

难的是转换成一般的函数怎么写呢?

Where是Enumerable的一个方法。

3.5才有的。

里面的参数是Func<

(Of<

(T,TResult>

)>

)泛型委托

Func<

ConvertMethod(string 

inString);

DelegateExample

reference 

UppercaseString 

ConvertMethod 

convertMeth 

UppercaseString;

name 

Dakota"

Use 

instance 

call 

Console.WriteLine(convertMeth(name));

UppercaseString(string 

inputString)

inputString.ToUpper();

写成泛型委托是

GenericFunc

string, 

string>

convertMethod 

Console.WriteLine(convertMethod(name));

于是应用到Linq,再变换到lambda

TestFunc(string 

fruit);

fruits 

=new 

apple"

banana"

mango"

orange"

blueberry"

grape"

strawberry"

TestFunc 

TestFunc(DoWork);

bool>

f2 

DoWork;

IEnumerable<

query 

fruits.Where(f2);

(string 

fruit 

query)

Console.WriteLine(fruit);

k.Length 

<

6;

能用。

passionfruit"

=k=>

也能用

fruits.Where(

k){

能用~

fruits.Where(k=>

k.Length<

6);

最后,lambda,能用~~~~就酱紫了~~~~

于是,我这个白痴,被自己写的教程搞明白了。

于是我也会了。

但是心情依旧很糟糕。

~~~~~~~~~

啊啊啊啊啊~最后来个有意思的!

mydg(int 

a, 

b);

LambdaTest

oper(this 

b, 

mydg 

dg)

dg(a, 

Console.WriteLine(1.oper(2, 

(a, 

b) 

b));

Console.WriteLine(2.oper(1, 

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 求职职场 > 简历

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1