I have read countless blogs, posts and StackOverflow questions about the new features of C# 4.0. Even new WPF 4.0 features have started to come out in the open. What I could not find and will like to know:
I think, internally, most changes are for the new dynamic languages and parallel programming. But are there any other major improvements? Because language improvements are just that, language improvements. You just need the new compiler and those features can be used with a lower version of .Net, apart from version 1.0/1.1 (at least most of them can be used).
And if the above features are the only ones, only for these features the version is changed to 4.0, which I think is 4.0 because of being based on .Net 4.0 version (i.e. after 1.0/1.1, 2.0 & 3.0/3.5). Is the version increment justified?
Edited:
As Pavel Minaev pointed out in the comments, even those two features are CLR independent. There were speed and other improvements in 3.0 and 3.5 also. So why the version increment?
One new CLR thing that I know about is a form of structural typing for interfaces, structs and delegates for the sake of NoPIA support - basically, it lets runtime treat distinct types with equivalent definitions as if they were the same - so if two assemblies A
and B
each have a COM-imported interface IFoo
declared in them, with the same IID and same members, runtime will treat them as equivalent types; so if there's an instance some class Foo
implementing [A]IFoo
, you can cast it to [B]IFoo
, and the cast will work.
One other thing is the ability to host several CLR versions side-by-side in a single process. You cannot host 1.x and 2.0 in one process, for example, but you can host 2.0 and 4.0. The main benefit for this is the ability to load plugins written for either CLR version concurrently.
One minor bit is that a few more exceptions have become uncatchable like StackOverflowException
was in 2.0 - you cannot catch AccessViolationException
anymore, for example.
Also, here is a PowerPoint presentation on CLR 4.0 from PDC 2008. It might be a bit dated now, but most stuff that's mentioned there seems to be in the betas.
There are a huge number of changes.
In the CLR itself, there are a few changes. The garbage collector is being changed to support concurrent collection of gen0/1 and gen2 in workstation mode. Also, there are some changes in how security is implemented. The parallel framework changes some of the CLR's implementation of the threadpool (which is not entirely managed, but part of the runtime itself). Also, there are some changes to the type system, mostly related to the new PIA COM support.
The biggest changes are probably more library/framework changes, rather than CLR changes. such as the integration of the DLR into the framework, and the new dynamic type. In terms of framework, you have the reactive framework, parallel library extensions, code contracts, tuple support, and lots of small changes (ie: Enum.TryParse
, Lazy<T>
, and tons of other small, but nice, improvements).
I don't believe there are any new IL instructions. The new CLR has improvements to things like inlining and garbage collection which do the same job as the 2.0 CLR, but better. A virtual machine (such as the CLR or JVM) is an abstract concept with multiple possible implementations. I believe CLR 4.0 is the same abstract machine as in CLR 2.0, just with an improved implementation.
Even the new dynamic stuff is just a compiler trick with new APIs (unlike in Java where it's being proposed as a new opcode.)
If I'm wrong about this, I'd love to know!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With