VB.Net - Objects

Objects

In the olden days objects were declared, and you could use the New aregument to create an instance of the object.

1
2
3
4
5
Dim mHome As New MenuItem()
mHome.Text = "Home"
mHome.Value = "Home"
mHome.NavigateUrl = "~/Default.aspx"
mnuMain.Items.Add(mHome)

Later VB introduced the With statement

1
2
3
4
5
6
Dim mHome As New MenuItem With {
.Text = "Home",
.Value = "Home",
.NavigateUrl = "~/Default.aspx"
}
mnuMain.Items.Add(mHome)

The with statement is also a standalone command

1
2
3
4
5
Dim student0 As New Student
With student0
.First = "Michael"
.Last = "Tucker"
End With

References