How do I perform an assignment operation in a lambda expression
I have a list of items and wish to set one of their properties to a certain value:
applist.ForEach(Function(x) x.PrePaidTypeID = CInt(DBEnums.PrePaidType.NoPrepay))
...but we think this just does a boolean comparison. Is there a way to force VB to assign the integer value rather than co开发者_高级运维mpare it?
Using a Sub lambda instead of a Function lambda will work. As you noticed, only in VS2010 do you get lamba Sub.
Another solution is to use a multiline lambda. This, too, only works in VS2010. :(
http://msdn.microsoft.com/en-us/library/bb531253.aspx
We're using VB .NET 9, which seems to be the issue here. In VB .NET 10 you can do the following which according to Google works:
applist.ForEach(Sub(x) x.PrePaidTypeID = CInt(DBEnums.PrePaidType.NoPrepay))
Using the Sub keyword means that it doesn't have to return a value so you can assign.
Looks like our solution is to update the project, or use a regular For Each loop.
精彩评论