tags:

views:

30

answers:

2

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 compare it?

+1  A: 

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.

GaryEmery
+1  A: 

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

Eyal