C# =>操作员? [英] C# => operator?

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

问题描述

我有一个关于 C# 中的 => 运算符的问题.

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

我正在查看 Expression Blend 4 示例.Contact 示例中有一行,其中包括:

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 ExpressionBlend 4SamplesenContacts
//ContactsViewModelsContactsViewModel.cs: 

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

   // Or, C:Program Files (x86)Microsoft ExpressionBlend 4Samplesen
   // ContactsContactsViewModelsContactsViewModel.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 表达式操作符,你可以把它想象成 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 和 E 的类型,因为它知道封闭委托的定义.

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天全站免登陆