Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use all C# 4.0 features in a project that targets .Net 3.5?

Development Environment : - VS2010 - .Net Framework 4.0, 3.5, 2.0

Staging and Production Environments: - .Net Framework 3.5, 2.0

The project I'm working on is targeting .Net Framework 3.5. And today I used optional parameters feature, which is new to C#4, in this project and it worked fine. I think VS2010 is using C#4 compiler and is compiling the method with optional parameters to corresponding overloaded methods in IL.

I want to know if I can use all new C#4 features as well.

like image 353
CleanCoder Avatar asked Aug 18 '10 22:08

CleanCoder


People also ask

Will all C code work in C++?

If the C++ compiler provides its own versions of the C headers, the versions of those headers used by the C compiler must be compatible. Oracle Developer Studio C and C++ compilers use compatible headers, and use the same C runtime library. They are fully compatible.

Can C and C++ be mixed?

C++ is a superset of C. Therefore, any valid C program is a valid C++ program, and there is no such thing as "mixing" C into C++.

Is C++ backwards compatible with C?

C++ is not fully backward compatible with C, wherever it's needed it has drawn a line.


1 Answers

You cannot use is the dynamic feature. This relies on the C# runtime and DLR DLL's which are only available on the 4.0 version of the .Net framework. Versions of the DLR are available for 3.5 but I do not believe they are compatible with the one required by the C# compiler.

Additionally you cannot use NoPIA / Embedded Interop Types in a down targetted scenario. This feature requires CLR support that was added in 4.0.

What's great about down targeting in Visual Studio 2010 though is you don't have to be aware of every limitation. If your projects are set to down target 3.5 and you use an incompatible feature, Visual Studio will produce an error.

like image 59
JaredPar Avatar answered Sep 30 '22 03:09

JaredPar