tags:

views:

28

answers:

1

I have a method that takes an System.Action, this is what I'm trying to feed it:

Function() Me._existingImports = Me.GetImportedAds()

The thing is that it complains about the = sign since it thinks I'm trying to do a comparison, which I'm not. I want to assign the Me._existingImports the value of Me.GetImportedAds(), but VB.NET complains about DataTable not having a = operator.

How can I force it to use the assignment operator instead of the equality operator?

In C# this works perfectly fine:

() => this.existingImports = this.GetImportedAds()

For now the solution will be to use a standalone method, but that's way more code than needed.

+4  A: 

When using Function(), you really define an anonymous function which means you map values to values.

Therefore Function() strictly needs an expression (like x or 42 ...) as the body, which an assignment is not! (Assignments don't evaluate to values like in C-style languages in VB)

Thus what you need is not a Function() but a Sub(), which contains statements (actions) rather than values.

Sub() Me._existingImports = Me.GetImportedAds()

C# doesn't distinguish here, the (much nicer) ... => ... syntax covers it all.

Dario
Well, I tried with Sub(), but that gives errors. This is using VS2008.
Kim Johansson
Yeah right. Anonymous `Sub()` have been added with VB2010 and unfortunately - up to that point - you don't really have a nice way of working around it.
Dario