gpt4 book ai didi

c# - 在 C# 中,=> 符号的含义

转载 作者:太空狗 更新时间:2023-10-29 20:10:41 32 4
gpt4 key购买 nike

有一个名为Student 的类,它具有属性IdNamePhone。在 UI 表单中,有一个 Student 列表,格式如下:

List<Student> students=new List<Student>();

最后是 dataGridview_Cellclick 事件的代码,其中使用了以下代码:

string id = dataGridview.Rows[e.RownIndex].Cells[0].Value.ToString();  
Student aStudent = students.Find(i=> i.Id== id);

students.Find(i=> i.Id== id) 有什么作用?这是什么意思? => 符号是什么意思?它是如何工作的?

最佳答案

它们称为 Lambda 表达式...Lambda 表达式使用特殊语法。它们允许将函数用作变量或字段等数据。 lambda 表达式语法使用 => 运算符。这样就把匿名函数的参数和语句体分开了。

您可以将其视为“Goes to”。

=> 运算符可以理解为“转到”,它总是在声明 lambda 表达式时使用。 lambda 表达式允许您使用带有可执行语句的函数作为参数、变量或字段。

参见 this link在 MSDN 上以更好地理解它。

关于c# - 在 C# 中,=> 符号的含义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13658078/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com