以 .NET 2.0 为目标时使用(某些)lambda 表达式?
ReSharper 建议我们将: 更改
System.Net.ServicePointManager.ServerCertificateValidationCallback +=
delegate(object sender, X509Certificate certificate, X509Chain chain,
SslPolicyErrors sslPolicyErrors)
{
return true;
};
为:
System.Net.ServicePointManager.ServerCertificateValidationCallback +=
(sender, certificate, chain, sslPolicyErrors) => true;
它看起来更干净一些。但我们的目标是.NET 2.0。这还是我们应该做的事情吗?
ReSharper suggests we change:
System.Net.ServicePointManager.ServerCertificateValidationCallback +=
delegate(object sender, X509Certificate certificate, X509Chain chain,
SslPolicyErrors sslPolicyErrors)
{
return true;
};
Into:
System.Net.ServicePointManager.ServerCertificateValidationCallback +=
(sender, certificate, chain, sslPolicyErrors) => true;
It looks a bit cleaner. But we are targeting .NET 2.0. Is this still something we should do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该选择其中您最喜欢的一个。在 C# 3.0 中引入的所有功能(例如 Lambda 表达式、扩展方法和 LINQ)都是基于 2.0 .NET 运行时构建的。所以你可以使用C#3.0进行开发并在运行时的2.0上运行。
只要您的编译器可以处理 C#3.0,您就可以使用所有新的 C#3.0 功能。我知道的唯一例外是,如果您使用表达式树,则需要使用 .NET 2.0 SP1,因为需要修复该服务包的 CLR 中的一些错误才能使表达式树正常工作。
You should choose which of them you prefer the most. In C# 3.0 all features introduced (such as Lambda expression, extension methods and LINQ) are build on the 2.0 .NET runtime. So you can develop using C#3.0 and run it on the 2.0 of the runtime.
As long as your compiler can handle C#3.0 you can use all the new C#3.0 features. The only exception I know of is that if you use Expression trees you'd need to use .NET 2.0 SP1 because some of the bug fixes in the CLR for that service pack is needed to make expression trees work properly.
只要使用VS2008(或更高版本)进行开发就可以使用。 Lambda 表达式是 C# 语言的一项功能,而不是 .Net Framework 的一项功能。
You can use it as long as you use VS2008 (or later) for development. Lambda expressions is a feature of C# language, it's not a feature of .Net Framework.