The c-sharp guy
The c-sharp guy

Reputation:

c# to vb conversion object initalization

I am trying to pick up on VB.net and have been programming in c# for a while. I have grasped pretty much most of vb.net but running into some issues with this conversion for object initialization:

CustomerParameters customerParameters = new CustomerParameters
                                               {
                                                   FirstName = "C First Name",
                                                   LastName = "C Last Name"
                                               };

Any thoughts on how to do this in VB, or if it is even possible?

Upvotes: 1

Views: 141

Answers (2)

D. Patrick
D. Patrick

Reputation: 3022

Dim cp As New CustomerParameters() With { _
     .FirstName = "C First Name", _
     .LastName = "C Last Name" _
}

Upvotes: 4

Joel Coehoorn
Joel Coehoorn

Reputation: 415745

I can't check it here, because the syntax requires VS2008 and I only have VS2005. But in VB.Net you need to use the With keyword to do initialization.

Dim c As New CustomerParameters() With { _
    .FirstName = "C First Name", _
    .LastName = "C Last Name" _
}

Yes, that's right. Curly braces in VB.

Upvotes: 1

Related Questions