[.NET] Return的作用?

看板Visual_Basic作者 (yllissuineg)時間14年前 (2011/05/23 11:30), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串1/1
之前練習用function時 對Return的理解是可以回傳某個值到某個變數 然後今天練習讀取文字時看到這串程式碼 Dim PATH As String = Console.ReadLine Dim txt As New FileInfo(PATH) Dim sr As StreamReader Try sr = txt.OpenText Catch ex As Exception Console.WriteLine(ex.Message) Console.ReadLine() Return End Try 然後我就不懂Return在這裡的意義了.... 他回傳了什麼嗎 試著把它拿掉的話 之後在使用sr.peek時就會顯示在指派之前使用....可能會產生null參考例外 怕之前的理解有誤,所以想請問一下Return的確切意思和作用? -- ◢◣◢◣ ◢█ ◢█ ● ◢◣ ◤█▊█ ◢◤█ ◢◤█◢ ◢ ◢◤ ▊▊█◤ ◥██◣ ◥██◤ ◢█ ◥█◤ ◢█ ◤█◤ ◢◤█ ◥█◤ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.4.196

05/23 12:55, , 1F
Return是離開,Function需傳回一個值,Sub不傳回值
05/23 12:55, 1F
文章代碼(AID): #1DsTJhp1 (Visual_Basic)