开发者

Can I use lambdas in a VB ASP.NET (2.0) project in VS 2008?

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 (Fu开发者_C百科nc(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) ?


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜