views:

38

answers:

1

I built a small chunk of code based around lambdas in a VB Windows form project earlier which works perfectly, but it gives me "expression expected" warnings (which block compiling... should probably be considered errors, no?) when I copy the code to an ASP.NET project. The only difference I can see is if I make a Windows form project vs a Web project... works in one, doesn't work in another.

Even something basic like this doesn't work:

delegate function stringify(byval x as object) as string
public sub test()
   dim f as stringify = Function(x) x.ToString()
   dim s as string = f(5)
end sub

Is there a way to get Lambdas to work in ASP.NET? Or is there a setting somewhere yanking my version of VB down a level or two (since they apparently only work in 9.0 or later, but I don't know how to tell which version I'm using)?

Edit: Bah! LinqBridge doesn't seem to work for me. I get the objects (Func(Of TResult)), but no lambda support. I suppose that's the death-knell to my hopes? Or is there something obvious I'm missing to use it (drag to bin, target in references, Imports System.Linq) ?

+1  A: 

You can if you use LinqBridge

It is an implementation of Linq for the .Net 2.0

As they say

LINQBridge is a reimplementation of all the standard query operators in Framework 3.5's Enumerable class.
...
In fact LINQBridge lets you use nearly all of the features in C# 3.0 with Framework 2.0 including extension methods, lambda functions and query comprehensions. The only feature it does not support is compiling lambdas to expression trees (i.e., Expression).

Carlos Muñoz
Awesome. I don't get to choose if I can use it, but that's great to know about. Know why ASP is behind even VB, though? It seems an odd disconnect, though I'll admit I'm pretty new to .NET. (I'll happily choose your answer if nobody comes up with a better way, I'd just like to know if there are other ways, preferably more along the lines of "check this box")
Groxx
Yes you can use it in ASP.NET but you should know that only covers LinqToObjects. It means it's no replacement to LinqToSQL. But You asked for the lambdas. You can have lambdas when you query IEnumerable<T> objects
Carlos Muñoz