tags:

views:

108

answers:

2
+2  A: 

The = operator pulls double duty for both assignment and equality in VB.Net. Is it possible it's being interpreted incorrectly as assignment here? Try this instead:

Dim count As Func(Of Integer, Boolean) = Function(x As Integer) Return x = 1
Joel Coehoorn
Na, underlined blue with "expression expected".
Saif Khan
+2  A: 

Your lambda function (checks whether ONE item is selected) and your stated goal (run message box if >1 items are selected) are not mutually exclusive. Neither covers the case when NO items are selected.

So if no items are selected, then "x=1" is false, so the "If" statement fails and you fall through to the message box.

What about writing

Dim count As Func(Of Integer, Boolean) = Function(x As Integer) (x <= 1)

??

Eric
underlined blue with "expression expected", but you are correct with the logic
Saif Khan
(edited to remove the return keyword)
Eric