当前位置: 首页 > 文档资料 > VB.Net 中文教程 >

随着...结束(With... End With)

优质
小牛编辑
131浏览
2023-12-01

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

此循环结构的语法是 -

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

编译并执行上述代码时,会产生以下结果 -

VB.Net Programming
Zara Ali
Information Technology