# Is it possible to use C# LINQ from Mathematica using .NET/Link?

Using Mathematica's .NET/Link (NETLink) package, is it possible to call out to .NET's LINQ facilities for list manipulation and other operations?

-
I think that there are two sides to this question: from the mathematica side and from the c# side. Could you explain which side you are asking for? As far as I can tell, from the c# side the answer is no. But, I am not familiar enough with LINQ to make a definitive answer. –  rcollyer Jan 23 '12 at 3:42
@rcollyer, Great point. Added a clarification in my question above. Still lacking clarity? –  sblom Jan 23 '12 at 3:45
Perfect. Exactly what I though you were asking. –  rcollyer Jan 23 '12 at 3:47

Yes, it is, but it's cumbersome (at least as of Mathematica 8). The hardest part is that you have to manually do a lot of the juggling required to work with .NET generics and extension methods.

For example, let's translate a straightforward solution to Project Euler's Problem #1 ("Add all the natural numbers below one thousand that are multiples of 3 or 5.") from LINQ:

Enumerable.Range(1, 999)
.Where(x => x % 5 == 0 || x % 3 == 0)
.Sum();


(* Load stuff. *)
InstallNET[];

(* Create our enumerable list of numbers. *)
numbers = EnumerableRange[1,999];

(* Create the filter that we're going to apply. *)
meths = enumerableType@GetMethods[];
whereMethod = First[Select[meths, #@Name == "Where" && Length[#@GetParameters[]] == 2&]];
EnumerableSum[filteredNumbers]
`