C#4.0的其他新功能是什么,动态和可选参数之后? [英] What are the other new features of C# 4.0, after dynamic and optional parameters?

查看:125
本文介绍了C#4.0的其他新功能是什么,动态和可选参数之后?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,C#4.0昨天出来了。它引入了非常争议的动态关键字,命名和可选参数。较小的改进是隐式的 ref 并且识别COM方法,反方和协方差(实际上是.NET CLR特性,而不是C#)的索引和默认属性。 ..

So, C# 4.0 came out yesterday. It introduced the much-debated dynamic keyword, named and optional parameters. Smaller improvements were the implicit ref and recognizing of indexed and default properties on COM methods, contra- and co-variance (really a .NET CLR feature, not C# only) and...

这是真的吗? 动态和可选/命名的参数是C#的唯一真正的改进吗?还是我错过了什么?不是我抱怨,但它似乎有点微不足道的C#2.0(泛型)和C#3.0(lambda,LINQ)。也许语言刚刚达到了实际的成熟度?

Is that really it? Are dynamic and optional/named params the only real improvements to C#? Or did I miss something? Not that I'm complaining, but it seems a bit meager after C# 2.0 (generics) and C# 3.0 (lambda, LINQ). Maybe the language just reached actual maturity?

推荐答案

关于锁和事件有一些非常小的更改,但通常这些不会明显。有关事件更改,请参见 Chris Burrows的博客系列;锁定请参见 Eric Lippert的博客。简而言之,锁定现在更可靠 - 它使用一个新的重载 Monitor.Enter ,以便它可以检测是否获取锁,即使面对异步异常。类似字段的事件现在是无锁的,在声明类中引用类似字段的事件访问器(add / remove)将引用事件而不是字段。

That's almost it, yes. There are some very minor changes around locking and events, but usually those won't be noticeable. For the event changes, see Chris Burrows' blog series; for locking see Eric Lippert's blog. In short, locking is now more reliable - it uses a new overload of Monitor.Enter so that it can detect whether the lock was acquired even in the face of asynchronous exceptions. Field-like events are now lock-free, and referring to a field-like event accessor (add/remove) in the declaring class will refer to the event rather than the field.

这绝对是比2和3更小的一组变化,但我认为这在许多方面都是一件好事 - 我认为开发者需要一定的时间为当前的功能睡觉。 2和3都是真正的大的功能发布...和一些功能仍然没有真正被广泛理解,IMO。

It's definitely a smaller set of changes than 2 and 3, but I think that's a good thing in many ways - I think devs need a certain amount of time for the current features to "bed in". Both 2 and 3 were really big feature releases... and some of those features still aren't really widely understood, IMO.

我确定不会是C#的演变的结束 - 我有一些想法,所以我敢打赌C#团队有更多 - 但只有这么多,可以打包到一个版本。虽然我怀疑大多数开发人员不会经常使用动态类型,这是一个巨大的变化语言本身,IMO - 一个非常复杂的事情,得到正确。我不感到惊讶,团队没有太多的时间在同一个发布周期创建更多的功能。

I'm sure that won't be the end of C#'s evolution - I've got some ideas, so I bet the C# team has rather more - but there's only so much that can be packed into one release. Although I suspect most developers won't actually use dynamic typing very often, it's a huge change in terms of the language itself, IMO - a very complex thing to get right. I'm not surprised the team didn't have much time to create many more features in the same release cycle.

不要忘记有VS2010工作太,将所有的新功能集成到Visual Studio本身,并处理非常重要的变化。

Don't forget there was VS2010 to work on too, integrating all the new features into that and working on the pretty significant changes to Visual Studio itself.

值得一提的是,尽管协方差和逆变绝对的CLR特性 - 确实已经从CLR v2.0开始 - 它们仍然是语言和库特性,就像泛型和可空值类型跨越CLR,框架和语言。

One thing that's worth mentioning is that although covariance and contravariance are definitely CLR features - and indeed have been since CLR v2.0 - they're still language and library features, just like generics and nullable value types spanned CLR, framework and language.

这篇关于C#4.0的其他新功能是什么,动态和可选参数之后?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆