Jump to content

  • Log In with Google      Sign In   
  • Create Account


Setting members in VB.NET without constructors


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Headkaze   Members   -  Reputation: 583

Like
0Likes
Like

Posted 12 November 2013 - 01:58 PM

In C# I can do the following:

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

Is there an equivalent in VB.NET?

Sponsor:

#2 jms bc   Members   -  Reputation: 415

Like
1Likes
Like

Posted 12 November 2013 - 03:50 PM

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"}


The Four Musketeers of Happiness have left.


#3 Headkaze   Members   -  Reputation: 583

Like
0Likes
Like

Posted 13 November 2013 - 05:41 AM

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?




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS