Tutorial :c# to vb conversion object initalization



Question:

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?


Solution:1

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


Solution:2

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.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »