如何在我的主模塊中創建一個類的實例?我一直沒有使用VB.NET(實際上大約兩天)我想要的是爲測試創建一個控制檯應用程序並創建不在主代碼文件中的類。如果它在同一個主模塊中,我可以創建一個類的實例,但是我不知道如何做的是創建一個實例,如果該類不在主模塊中。Visual Basic .NET想在我的主模塊中創建一個類文件實例?
類文件:
Public Class Class1
Dim cText As String
End Class
主要模塊:
Module Module1
Sub Main()
Dim oLine As New Line("a", "b", "c")
oLine.setYourName = "testName-testName"
Class1 h As new Class1() <--Error at this line
Console.WriteLine(oLine.setYourName)
Console.ReadLine()
End Sub
End Module
Public Class Line
Private mstrLine As String
Private mstrTest As String
Friend Text As String
Public Sub New()
Console.WriteLine("Zero-Arguement Construtor")
End Sub
Public Sub New(ByVal Value As String)
Console.WriteLine("One-Arguement Construtor")
End Sub
Public Sub New(ByVal Value As String, ByVal v As String, ByVal a As String)
Console.WriteLine("Three-Arguement Construtor")
End Sub
Public Sub TextFileExample(ByVal filePath As String)
' Verify that the file exists.
If System.IO.File.Exists(filePath) = False Then
Console.Write("File Not Found: " & filePath)
Else
' Open the text file and display its contents.
Dim sr As System.IO.StreamReader = System.IO.File.OpenText(filePath)
Console.Write(sr.ReadToEnd)
sr.Close()
End If
End Sub
Public Function GetWord() As String
Dim astrWords() As String
astrWords = Split(mstrLine, " ")
Return astrWords(0)
End Function
Property setYourName() As String
Get
Return Text
End Get
Set(value As String)
Text = value
End Set
End Property
Property Line() As String
Get
Return mstrLine
End Get
Set(ByVal Value As String)
mstrLine = Value
End Set
End Property
ReadOnly Property Length() As Integer
Get
Return mstrLine.Length
End Get
End Property
End Class
什麼是錯誤 – Jade