开发者

VB.NET: Which As clause to use with anonymous type with Option Strict On?

开发者 https://www.devze.com 2023-01-11 12:51 出处:网络
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 an开发者_开发百科onymous type?

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 an开发者_开发百科onymous type?

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

What will follow the As?


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


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消