Search This Blog

Tuesday, January 22, 2013

With...End With Statement (VB.NET)

VB.NET > Statements > With...End With

Executes a series of statements that repeatedly refers to a single object or structure.

By using With...End With, you can perform a series of statements on a specified object without specifying the name of the object multiple times.

Example:


Public Class Form1
  Private Class Customer
    Public Property Id As String
    Public Property Name As String
  End Class
  Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    With New Customer
      .Id = 1
      .Name = "Elsoft"
      MessageBox.Show(.Name)
    End With
  End Sub