C# lambda 表达式的转换
将以下内容转换为 lambda 表达式的方法是什么?
ThreadPool.QueueUserWorkItem(delegate
{
Console.WriteLine("Current Thread Id is {0}:",
Thread.CurrentThread.ManagedThreadId);
Console.WriteLine("I will be used as Callback");
}
);
What is the way to convert the following into lambda expression?
ThreadPool.QueueUserWorkItem(delegate
{
Console.WriteLine("Current Thread Id is {0}:",
Thread.CurrentThread.ManagedThreadId);
Console.WriteLine("I will be used as Callback");
}
);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您绝对可以将其写为 lambda 表达式:
但请记住,lambda 表达式在源代码之外没有任何意义。 C# 编译器会将您的 lambda 表达式直接转换回您现在的代码。
lambda 表达式只是语法糖,可用于表达匿名函数 - 编译器会将其转换为匿名函数或表达式树。
You could definitely write this as a lambda expression:
But remember that a lambda expression has no meaning outside of your source code. The C# compiler will convert your lambda expression right back to the code you have now.
A lambda expression is simply syntactic sugar that you can use to express an anonymous function - the compiler will convert this to either an anonymous function or an expression tree.