Reputation: 2868
What are the changes I need to make to a application built with .NET 2.0 /C# in order to use the C# 4.0 features . Recently I ran into a problem, when trying to add optional paramters in a product which was developed on .NET 2.0 / C# 2.0 .
Upvotes: 0
Views: 6842
Reputation: 884
One problem, that I ran into recently when upgrading a 3.5 project to 4.0 (Visual Studio 2008 to Visual Studio 2010), was that after upgrading to 4.0 I did not have a reference to System.Core
and was unable to add it via Visual Studio instead displaying a message:
A reference to 'System.Core' could not be added. This component is already automatically referenced by the build system.
You will need to have a reference to System.Core
if you want to use the var
keyword and LINQ extension methods.
It can be manually added (or readded if removed). See the blog post System.Core in VS2010 Projects for details.
Upvotes: 1
Reputation: 11397
You can't easily convert form a higher version to a lower version.
You can easily convert form a lower version to a higher version.
Upvotes: 0
Reputation: 38545
C# in .NET 2.0 does not support optional parameters if I remember correctly.
Upvotes: -1
Reputation: 266
Most 2.0 programs works without any changes on 4.0. It was only on 1.1 to 2.0 that there was a lot of incompatible changes.
Upvotes: 2
Reputation: 1039368
You cannot use .NET 4.0 specific features in an application targeting .NET 2.0. You will need to migrate to .NET 4.0.
Upvotes: 0
Reputation: 30912
In theory, C# 4 should be backwards compatible with C# 2.
In practice, I've done it several times with no problems, and I think the only obvious problem is if you have named some classes that are defined by the .net 4.0 framework.
Upvotes: 0
Reputation: 64943
Maybe you migrated your Visual Studio solution to 2010, but you forgot to change the target framework to 4.0 in projects' properties.
Just go to properties in your solution projects (obviously, the migrated to Visual Studio 2010 solution) and change the target framework to 4.0.
That's all your C# code base will be using .NET Framework 4.0 and C# 4.0. I'm pretty sure you won't need to change your code, but, maybe, you'll find that some classes, methods, properties are now obsolete, but it'll compile anyway.
Comment out if you don't know how to do that.
Upvotes: 0