• Advertisement
Sign in to follow this  

Setting members in VB.NET without constructors

This topic is 1530 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In C# I can do the following:

MyClass myObject = new MyClass() { Member1 = value1, Member2 = value2, Member3 = value3 };

Is there an equivalent in VB.NET?

Share this post


Link to post
Share on other sites
Advertisement

found this example

 

Public Class Customer

    Public Id As Integer

    Public Name As String

End Class

 

then, you can

 

Dim cust = New Customer() With {.Id = 2, .Name = "VB.NET 9.0"}

Share this post


Link to post
Share on other sites
That's great thanks. Never seen curly brackets used like that in VB.NET before. Is this feature only available to Visual Studio 9 (2008) and higher?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement