()=> 有什么用?银光闪闪 [英] what is the use of ()=> in silverllight

查看:12
本文介绍了()=> 有什么用?银光闪闪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你能说说()=>=>的作用是什么?我在代码中看到了这一点.我没有得到任何参考.

Can you say what is the use of the ()=> and =>? I saw this in a code. I did not get any reference for this.

this.Dispatcher.BeginInvoke(()=>
{
    //some thing..
};

推荐答案

此表示法是 lambda 表达式 不带参数.如果 lambda 表达式使用参数,它们将在括号的空集中声明,如 say...

This notation is that of a lambda expression which takes no argument. If the lambda expression made use of arguments they would be declared in the empty set of parenthesis as in say...

this.Dispatcher.BeginInvoke((x, y) => { do some' with x and/or y }, 12, somevar);

简而言之,lambda 表达式允许在需要的地方创建无名"函数.
在问题的示例中,BeginInvoke() 方法要求它的第一个参数是一个委托(指向方法的指针"),这正是这个 lambda 表达式所提供的.

In a nutshell, lambda expressions allows creating "nameless" functions, right where they are needed.
In the example of the question, the BeginInvoke() method requires its first parameter to be a delegate (a "pointer to a method"), which is exactly what this lambda expression provides.

这篇关于()=> 有什么用?银光闪闪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆