C# to VB.NET syntax conversion for class instantiation with properties

北城以北 提交于 2019-12-04 00:28:48

问题


I am working with Workflow Foundations 4 (in C#) and am trying to write a VB.NET expression. Is there a way to do the following in VB.NET on one line?

SomeObj instance = new SomeObj()
{ 
    SomeStringProp = "a",
    SomeIntProp = 17
};

回答1:


Here's an example:

Dim instance = new SomeObj() With {
    .ISomeStringProp = "a", 
    .SomeIntProp = 17
}

If you want more info take a look at VB.NET 9.0: Object and Array Initializers.



来源:https://stackoverflow.com/questions/3936224/c-sharp-to-vb-net-syntax-conversion-for-class-instantiation-with-properties

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