C# to VB.NET syntax conversion for class instantia

2019-02-16 13:42发布

问题:

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.