Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dynamic keyword problem

Tags:

c#

.net

dynamic

pls tell me in which version dynamic keyword is introduced ? I found strange behavior in VS2010. I set target framework to 3.5. But there is no compiler error. just crate a console application with target framework to .net 3.5 and use dynamic keyword .

like image 369
Saokat Ali Avatar asked Dec 31 '10 06:12

Saokat Ali


2 Answers

The dynamic type was introduced in .Net 4.0.

The dynamic type is not a language only feature (i.e purely supported by the compiler). It relies on the DLR which is a .Net 4.0 feature which needs library support.

You cannot use dynamic and target the .Net 3.5 framework.

like image 73
Tim Lloyd Avatar answered Oct 17 '22 08:10

Tim Lloyd


When you use Visual Studio 2010, it defaults to C# 4.0.

You can not use C# 3.0 with Visual Studio 2010.

Even if you target .Net Framework 3.5, it will just use Framework 3.5 and not C# 3.0.

Now, since it defaults to C# 4.0, you get to use dynamic. But for that to work, you have to reference Microsoft.CSharp.dll. That assembly is compiled with v 4.0. You can't use it under v 3.5.

dynamic needs DLR (Dynamic Language Runtime) which is not there for previous framework versions.

That is why when you try to use dynamic under Framework 3.5 project, it will freak out.

So, to summarize, to use dynamic, use Framework 4.0.

like image 41
decyclone Avatar answered Oct 17 '22 10:10

decyclone