2

我不确定我做错了什么。

我查看了此功能的开发人员帮助页面,但没有任何示例

GetTempPath 帮助

现在我只想将临时目录打印到 msgbox 以确保我做对了。然后我将使用它来写入文件

我是 VB.net 新手,更熟悉 C

这是我的代码:

Imports System
Imports System.IO
Imports System.Collections

Public Class Form1

Public Shared Function GetTempPath() As String
End Function

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    ...
    ...

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim tempFolder As String
    tempFolder = GetTempPath()
    MsgBox(tempFolder)
End Sub

省略号仅表示该问题不需要的代码

4

1 回答 1

2

您需要删除您的Function声明GetTempPath。这导致您使用您的功能,而不是System.IO.Path版本。既然Path.GetTempPath是 a Shared Function,你就可以通过Path.GetTempPath().

您的代码应如下所示:

Imports System
Imports System.IO
Imports System.Collections

Public Class Form1

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    ...
    ...

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim tempFolder As String
    tempFolder = Path.GetTempPath()
    MsgBox(tempFolder)
End Sub
于 2013-08-08T17:20:21.760 回答