tags:

views:

208

answers:

3

I've heard the claim before that .Net 3.5 made no changes to the IL that it compiles to. Upon thinking through all of the compiler features that I know were introduced, it does, in fact, seem that they could all be implemented in the same old IL, but I can't find an official source to corroborate this claim. Is it true?

+4  A: 

I think that there haven't been any IL changes as such, but there have been significant changes within the CLR implementation to make dynamic methods more efficient, allow for expression tree compilation etc. I seem to remember there have been changes around security of building dynamic methods, to make it feasible for lambda expressions generating expression trees to call private methods to work even in relatively low trust environments. The compiler knows that it's valid to call the private method because the point at which the source code is compiled has access to it. Proving that is tricky though :) See this note by Eric Lippert.

Jon Skeet
The IL hasn't changed but the compiler will have. We've noticed, for instance, that the internal tools in WCF create quite different C# for proxies and the like, which will in turn create different IL when compiled.See also the discussion of "red bits" and "green bits" in Soma's log entry http://blogs.msdn.com/somasegar/archive/2006/05/18/601354.aspx.
Jeremy McGee
A: 

The shipping CLR (Version 2.0.50727) has not changed since .NET 2.0, so your IL is identical. (See also this SO QA)

Peter Stuer
No, the CLR itself *has* changed - part of .NET 2.0 SP1 was a CLR change, I believe.
Jon Skeet
There have been several releases of the Version 2.0.50727 CLR since the original .NET framework 2.0 release. The original RTM release was e.g. Version 2.0.50727.42 . On my machine (Vista SP2) the full version is Version 2.0.50727.4016. However, AFAIK there have been no functional changes since the original release.
Peter Stuer
A: 

..and as a result, if you wanted, you could use a lot of .NET 3.5 features in a .NET 2.0 project, as long as you use the latest compiler:

  • Automatic properties
  • Extension methods (requires a little dirty trick tho)
  • Object initializers
  • Type inference (var keyword)
  • Lambda expressions
Thorarin