views:

43

answers:

2

Consider the requirement to always declare Option Strict On. We'll always need to declare variables with the As keyword. What would be the type of an anonymous type?

Example : Dim product As ... = New With { Key .Name = "paperclips", .Price = 1.29 }

What will follow the As?

+1  A: 

Add an Option Infer On statement, then you don't use As. If you don't use Option Infer On, product will be of type Object (but you'd have to make Option Strict Off to compile). With type inference on, it will be type (compiler generated).

Richard Hein
+2  A: 

try either setting Option Infer On at the top of the class or a project level

Iain
+1 To be clear, you are also allowed to have `Option Strict On` and `Option Explicit On` with `Option Infer On`. You should always keep `Option Strict On` and `Option Explicit On`.
MarkJ