C#=>运营商? [英] C# => operator?

查看:96
本文介绍了C#=>运营商?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题 =方式> 运算符在C#

I have a question about the => operator in C#.

我在看防爆pression混合4个样本。有接触样品,它包括在一个行:

I am looking at the Expression Blend 4 samples. There is one line in the Contact sample which includes:

//In C:\Program Files (x86)\Microsoft Expression\Blend 4\Samples\en\Contacts\
//Contacts\ViewModels\ContactsViewModel.cs: 

contactDetailWindow.Closed += (o, e) =>
{                              
   finishedCallback(contactDetailWindow.DialogResult);

   // Or, C:\Program Files (x86)\Microsoft Expression\Blend 4\Samples\en\
   // Contacts\Contacts\ViewModels\ContactsViewModel.cs
   this.EditContact(newContact, dialogResult =>
   {
        if (dialogResult.HasValue && dialogResult.Value)
        {
        this.Contacts.Add(newContact);
        }
   });
};

什么是 => 运营商实际上是在做什么?难道是压倒一切的东西吗?

What is the => operator actually doing? Is it overriding something?

推荐答案

=>是一个lambda前pression运营商可以把它看成在JavaScript中的匿名函数

=> is a lambda expression operator you can think of it as an anonymous function in javascript

在这种情况下

ContactDetailWindow.Closed += (o, e) => { finishedCallback(contactDetailWindow.DialogResult);

它正在创建正被用作处理程序闭合事件的功能。该编译器可以推断类型O和电子商务,因为它知道的封闭delelegate的确定指标。

it is creating a function that is being used as the handler for the closed event. The complier can infer the types of o and E since it knows the defintion of of the closed delelegate.

这篇关于C#=>运营商?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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