VB.Net - With... End With语句

2022-06-02 15:12 更新
With... End With语句不是一个循环结构。 它执行一系列反复引用单个对象或结构的语句。

这个循环结构的语法是:

With object
    [ statements ]
End With

示例:

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

以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号