3

Is it possible to run a LINQ method using normal LINQ if the Net Framework 3.5 is installed, but using PLINQ instead if 4.0 or higher is installed ?

2
  • 4
    I think it is unwise to implement 2 pieces of code that perform the same task unless there is a really big advantage. This would double the probability of bugs, and potentially lead to inconsistent behavior that is twice as hard to track down. Commented Oct 31, 2010 at 0:11
  • I agree, I don't think this would be good practice in general. The alternatives - always code for the 'lowest common denominator' framework, or force your clients to upgrade - aren't that attractive either though. I was just wondering if there was an additional option, kind of like how web designers can code their sites to look great in newer browsers and degrade gracefully in older ones. Commented Oct 31, 2010 at 10:38

2 Answers 2

2

I don't think that's possible. Here are some alternatives:

  • If it is at all an option it would be much simpler to require your users to upgrade to .NET 4.0.
  • If you can't require your users to upgrade you can spend a little more time improving the .NET 3.5 code so that you don't need to make a special .NET 4.0 version.
  • Or you can make two different builds of your project using #if directives.
Sign up to request clarification or add additional context in comments.

Comments

0

While i also don't think its wise to code two versions you can use the Environment.Version variable.

It is there in all .net versions since 1.1 and Silverlight.

1 Comment

I'm aware of Environment.Version, but I can't see it would work here. To get the optional PLINQ code to compile I'd have to set Target Framework to 4.0, and in that case it wouldn't run on machines without the 4.0 Framework installed. If you disagree, can you post example code ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.