Reputation: 61606
I've been really loving this extension method in my .NET 4.0 code:
public static bool In<T>(this T source, params T[] list)
{
if(null==source) throw new ArgumentNullException("source");
return list.Contains(source);
}
Now, I'd really like to use it in my .net 3.5 project, but it's missing the Contains method. How can I cleanly downgrade this extension method without complicating things too much?
Upvotes: 1
Views: 596
Reputation: 117064
I agree with James Gaunt, this should run under 3.5 as is.
Perhaps you have neglected to add the using System.Linq;
and using System.Collections.Generic;
declarations at the top of your code?
I get caught by that all the time.
Upvotes: 2
Reputation: 14783
Contains is an extension on IEnumerable introduced in 3.5 as part of LINQ. This code will compile under 3.5.
If it's not then make sure you have included
using System.Linq
Upvotes: 9