none
vb.net equivalent of c# new variable declaration with property assignment RRS feed

  • Question

  • Hey everyone
    I'm working on a VB.NET project now but it's been years since I last used VB.NET
    I've only been using C# so far and I'd like to know if the following is possible in VB.NET
     
    MyClass myClass = new MyClass()
    {
    Property1 = "hello",
    Property2 = "world",
    Property3 = 5
    }
    

    I've tried bing'ing it but since I'm not sure what this kind of statement is called I had no idea what to look for.
    I assume it could have something to do with the "With" statement?

    Kind regards,

    Dirk Schuermans
    Microsoft Student Partner
    Wednesday, December 21, 2011 10:56 AM

Answers

  • Hm, think I've solved my own question :x

    Dim itemWrapper As New HtmlGenericControl("div") With {.ID = "Wrap"}
    


    Kind regards,

    Dirk Schuermans
    Microsoft Student Partner
    • Marked as answer by Schuermans Dirk Wednesday, December 21, 2011 12:02 PM
    Wednesday, December 21, 2011 11:03 AM

All replies

  • Hm, think I've solved my own question :x

    Dim itemWrapper As New HtmlGenericControl("div") With {.ID = "Wrap"}
    


    Kind regards,

    Dirk Schuermans
    Microsoft Student Partner
    • Marked as answer by Schuermans Dirk Wednesday, December 21, 2011 12:02 PM
    Wednesday, December 21, 2011 11:03 AM
  •  

    Thank you for sharing your solution here. It will be very beneficial for other community members who have similar questions. 

    Have a nice day.


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Thursday, December 22, 2011 3:37 AM