Visual Basic With… End With 语句

With… End With 语句不完全是一个循环的结构。它执行一系列重复引用单个对象或结构的语句。

这个循环结构的语法是:

  1. With object
  2. [ statements ]
  3. End With

实例

  1. Module loops
  2. Public Class Book
  3. Public Property Name As String
  4. Public Property Author As String
  5. Public Property Subject As String
  6. End Class
  7. Sub Main()
  8. Dim aBook As New Book
  9. With aBook
  10. .Name = "VB Programming"
  11. .Author = "Zara Ali"
  12. .Subject = "Information Technology"
  13. End With
  14. With aBook
  15. Console.WriteLine(.Name)
  16. Console.WriteLine(.Author)
  17. Console.WriteLine(.Subject)
  18. End With
  19. Console.ReadLine()
  20. End Sub
  21. End Module

结果如下:

  1. VB Programming
  2. Small Su
  3. Information Technology

分类导航