你能说什么()=>和=>的用法吗? 我在代码中看到了这一点。 我没有得到任何参考。
this.Dispatcher.BeginInvoke(()=> { //some thing.. };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表达式使用参数,它们将在空括号中声明,如说...
this.Dispatcher.BeginInvoke((x, y) => { do some' with x and/or y }, 12, somevar);
简而言之,lambda表达式允许在需要的地方创建“无名称”函数。 在问题的例子中, BeginInvoke()方法要求它的第一个参数是委托(一个“指向方法的指针”),这正是lambda表达式提供的。
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);
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.
更多推荐
发布评论