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

可紊 提交于 2019-12-11 03:04:44

问题


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:


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




回答2:


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



来源:https://stackoverflow.com/questions/3451434/vb-net-which-as-clause-to-use-with-anonymous-type-with-option-strict-on

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!