Option Strict and anonymous types do not go together?

I have a Linq query that gives anonymous types. However, now I want to work with the parameters of this anonymous type and it does not seem to work.

For Each obj As Object in Query
Dim row As DataRow = obj.parameter
...
Next obj

Now the compiler throws an error in the expression obj.parameter: "Option Strict On prohibits late binding." If I understand correctly, the compiler does not know the parameters of an anonymous type. I tried the Infer On option (and deleted as an object) based on Google results, but that didn't help. This seems to make sense, because it always seems to be an expanding appeal to me.

Is there a way to fix this, or should I just create my own type?

+5
source share
1 answer

, (.. Select LINQ), , , , Query . , Object, , .

, LINQ (, , , Select ) . .

Dim Query = From prod In products
            Select prod.Name, prod.Price

For Each obj in Query
    Dim name = obj.Name
    ...
Next obj
+4

All Articles