VB.Net - With... End With語句

2022-06-02 15:12 更新
With... End With語句不是一個循環(huán)結(jié)構(gòu)。 它執(zhí)行一系列反復(fù)引用單個對象或結(jié)構(gòu)的語句。

這個循環(huán)結(jié)構(gòu)的語法是:

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

當上述代碼被編譯和執(zhí)行時,它產(chǎn)生以下結(jié)果:

VB.Net Programming
Zara Ali
Information Technology

以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號