Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are some C#4 features allowed even when targeting 3.5?

We upgraded to VS 2010, but we haven't yet upgraded to .NET 4.0. All of our projects are still explicitly targeting 3.5.

Today, a developer checked in code that looked like this:

delegate T Generator<out T>();

As far as I know, "in T" and "out T" are C# 4.0 features. According to our build server, which doesn't have .NET 4.0 installed on it, I'm right. The check-in broke the build. But, why the heck does it build on his machine? Why is VS just ignoring the target framework for the project?

Other C# 4.0 features, like the dynamic keyword, do not build on the developer's machine.

like image 214
Greg Smalter Avatar asked Dec 17 '22 01:12

Greg Smalter


1 Answers

The C# spec is developed separately from the CLR. This means that if a C# feature can be translated into code for an earlier version of .NET, it can still be used when targeting the earlier version of the framework.

like image 83
zildjohn01 Avatar answered Jan 06 '23 16:01

zildjohn01