This is a question for my curiosity really, as i know there are other ways to work around the problem.
I have a property on my “Item” class – “MyProperty” – that I want to evaluate. I want to iterate through the collection – “MyItemCollection” – , and if there is an “Item” class whos property “MyProperty” is not nothing i want to set a Boolean flag to indicate that the collection contains a non null MyProperty on any of its “Item” Objects.
Private ContainsPOF = Function() (From thisItem As Item In MyItemCollection Where Item.MyProperty IsNot Nothing Select item).Count > 0
This gives me a warning of “Variable decleration without an ‘As’ clause; type of Object assumed”, so i tried
Private ContainsPOF As Boolean = Function() (From thisItem As Item In MyItemCollection Where Item.MyProperty IsNot Nothing Select item).Count > 0 subc).Count > 0
This however gives me the error of “Lamda expression cannot be converted to ‘Boolean’ As ‘Boolean’ is not a delegate type”
Is there anyway to make the return of this Function type safe, or should I just use a different method (an old style Function)?
Thanks.
I think you want to declare it as
Func(Of Boolean)instead:As far as I can see that’s not creating a property (as per your first paragraph) though. Why not declare it as a normal property?