Steve
Steve

Reputation: 579

Object initializers and With keyword

In reference to VB.Net and not to be confused with; With/End With (I think?)

Dim cust0 As Customer = New Customer With {.Name = "Toni Poe", 
                                           .City = "Louisville"}

Object Initializers: Named and Anonymous Types (Visual Basic)

Question: I cannot find any direct reference to the use of With in the above context. I understand how it is used but cannot find any documentation on MSDN about its use, other than from the link I've included, and even there it's not specifically referenced or explained.

There may be no more there there...? And while I'm pretty sure it's not related to the more dated With/End With usage, I'd just like to find a more detailed description of it's use. Anyone? Thanks.

Upvotes: 3

Views: 383

Answers (1)

Steve
Steve

Reputation: 579

So I did find this, reference to With as a keyword versus statement. So they are different creatures, though kind of sort of related. There doesn't appear to be an entry in MSDN specifically for With as keyword.

With...End With Statement (Visual Basic)

You can use the With keyword in object initializers also. For more information and examples, see Object Initializers: Named and Anonymous Types (Visual Basic) and Anonymous Types (Visual Basic).

Upvotes: 1

Related Questions