C# 2.0 code consuming assemblies compiled with C# 3.0

Question :

C# 2.0 code consuming assemblies compiled with C# 3.0,

Answer :

This should be fine seeing as the CLR hasn’t actually changed?

The boxes running the C# 2.0 code have had .NET 3.5 rolled out.

The background is that we have a windows service (.NET 2.0 exe built with VS2005, deployed to ~150 servers) that dynamically loads assemblies (almost like plug-ins) to complete various work items asked of it. Whenever we roll out a new version of the bus logic, we just drop the assemblies on an FTP server and the windows service knows how to check for, grab and store the latest versions. New assemblies are now built using VS2008 and targetting .NET 2.0, we know that works ok. However we’d like to start taking advantage of C# 3.0 language features such as LINQ and targetting the assemblies against .NET 3.5 without having to build and deploy a new version of the windows service.

Read More  Calculating Distance Between 2 Cities

,

C#3 and .Net 3.5 adds new assemblies, but the IL is unchanged.

This means that with .Net 2 assemblies you can compile and use C#3, as long as you don’t use Linq or anything else that references System.Linq or System.Core

yield, var, lambda syntax, anon types and initialisers are all compiler cleverness. The IL they produce is cross-compatible.

If you can reference the new assemblies for 3.5 it should all just work.

There is no new version of ASP.Net – it should still be 2.0.50727 – but you should still compile for 3.5

Read More  F# curried function

That’s the answer C# 2.0 code consuming assemblies compiled with C# 3.0, Hope this helps those looking for an answer. Then we suggest to do a search for the next question and find the answer only on our site.

Disclaimer :

The answers provided above are only to be used to guide the learning process. The questions above are open-ended questions, meaning that many answers are not fixed as above. I hope this article can be useful, Thank you