VB.Net - With... End With Statement

Advertisements


It is not exactly a looping construct. It executes a series of statements that repeatedly refers to a single object or structure.

The syntax for this loop construct is:

With object
    [ statements ]
End With

Example

Module loops
   Public Class Book
      Public Property Name As String
      Public Property Author As String
      Public Property Subject As String
   End Class
   Sub Main()
      Dim aBook As New Book
      With aBook
          .Name = "VB.Net Programming"
          .Author = "Zara Ali"
          .Subject = "Information Technology"
      End With
      With aBook
          Console.WriteLine(.Name)
          Console.WriteLine(.Author)
          Console.WriteLine(.Subject)
      End With
      Console.ReadLine()
   End Sub
End Module

When the above code is compiled and executed, it produces the following result:

VB.Net Programming
Zara Ali
Information Technology


Advertisements
Advertisements