Sign in to follow this  
Headkaze

Setting members in VB.NET without constructors

Recommended Posts

Headkaze    607
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
jms bc    448

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
Headkaze    607
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this