什么是 () => //js 或 C# 中的示例代码
Waht is () => //sample code in js or C#
()=> //codes
叫什么名字
它有什么作用?或者它的目的是什么。 c#
中的示例
List<Task> Tasks = new List<Task>();
var taskCustomer = Task.Factory.StartNew(() =>
{
using (NorthContext dbContext=new NorthContext())
{
model.CustomerList = dbContext.Customers.Where(
cus=>cus.ContactName.Contains(search)).ToList();
}
});
Tasks.Add(taskCustomer);
js 中的示例
window.addEventListener('resize', () => this.onResize());
this.onResize();
在javascript/Typescript
中,它被称为arrow function
,
FROM DOCS
An arrow function expression has a shorter syntax than a function
expression and does not have its own this, arguments, super, or
new.target. These function expressions are best suited for non-method
functions, and they cannot be used as constructors.
在C#
,
A lambda expression is an anonymous function that you can use to
create delegates or expression tree types. By using lambda
expressions, you can write local functions that can be passed as
arguments or returned as the value of function calls. Lambda
expressions are particularly helpful for writing LINQ query
expressions.
这个() => {//...}
在C#中被称为lambda表达式。这是定义方法并将其作为参数传递给另一个方法的简单方法。在这种 specific 情况下,您定义的方法没有参数,并且执行您在大括号内指定的任何操作。更正式的说法是 here:
A lambda expression is an anonymous function that you can use to
create delegates or expression tree types. By using lambda
expressions, you can write local functions that can be passed as
arguments or returned as the value of function calls. Lambda
expressions are particularly helpful for writing LINQ query
expressions.
另一方面,在 JavaScript 中,这称为 箭头函数 并且如前所述 here:
An arrow function expression has a shorter syntax than a function
expression and does not have its own this, arguments, super, or
new.target. These function expressions are best suited for non-method
functions, and they cannot be used as constructors.
()=> //codes
它有什么作用?或者它的目的是什么。 c#
中的示例 List<Task> Tasks = new List<Task>();
var taskCustomer = Task.Factory.StartNew(() =>
{
using (NorthContext dbContext=new NorthContext())
{
model.CustomerList = dbContext.Customers.Where(
cus=>cus.ContactName.Contains(search)).ToList();
}
});
Tasks.Add(taskCustomer);
js 中的示例
window.addEventListener('resize', () => this.onResize());
this.onResize();
在javascript/Typescript
中,它被称为arrow function
,
FROM DOCS
An arrow function expression has a shorter syntax than a function expression and does not have its own this, arguments, super, or new.target. These function expressions are best suited for non-method functions, and they cannot be used as constructors.
在C#
,
A lambda expression is an anonymous function that you can use to create delegates or expression tree types. By using lambda expressions, you can write local functions that can be passed as arguments or returned as the value of function calls. Lambda expressions are particularly helpful for writing LINQ query expressions.
这个() => {//...}
在C#中被称为lambda表达式。这是定义方法并将其作为参数传递给另一个方法的简单方法。在这种 specific 情况下,您定义的方法没有参数,并且执行您在大括号内指定的任何操作。更正式的说法是 here:
A lambda expression is an anonymous function that you can use to create delegates or expression tree types. By using lambda expressions, you can write local functions that can be passed as arguments or returned as the value of function calls. Lambda expressions are particularly helpful for writing LINQ query expressions.
另一方面,在 JavaScript 中,这称为 箭头函数 并且如前所述 here:
An arrow function expression has a shorter syntax than a function expression and does not have its own this, arguments, super, or new.target. These function expressions are best suited for non-method functions, and they cannot be used as constructors.