是否有可能在兩個不同的類中具有相同的變量定義。 我剛開始學習vb.net,我試圖實現地址驗證API,到目前爲止,UPS類適用於跟蹤詳細信息,但UPS地址不。兩個類別之間唯一不同的是路徑變量和構造函數的參數。可以在vb.net的不同類中使用相同的變量定義
Public Class UPS
Private accessKey As String = "0D0F94260Dxxxxx"
Private userName As String = "xxxxxx"
Private passWord As String = "xxxxx"
Private path As String = "https://www.ups.com/ups.app/xml/Track"
Public xml As XmlDocument = New XmlDocument()
public Sub New(trackNo As String)
xml = getUPSXMLbyTrackingNumber(trackNo)
End Sub
Public Function getIdentificationNumber() As String
Dim idNo As String = getNodeValue(xml, "TrackResponse/Shipment/ShipmentIdentificationNumber")
Return idNo.Trim
End Function
End Class
這是另一類。
Public Class UPSAddress
Private accessKey As String = "0D0F94260Dxxxxx"
Private userName As String = "xxxxxxx"
Private passWord As String = "xxxxxxx"
Private path as String = "https://wwwcie.ups.com/ups.app/xml/XAV"
Public xml As XmlDocument = New XmlDocument()
public Sub New(Address As String,City as String,State as String,Zipcode as String)
xml = getUPSXMLAddressValidation(Address,City,State,Zipcode)
End Sub
end class
此方法是否正確?這就是我稱之爲VB編譯器中的類的方法
Dim trackNo As String = upsTrackNo.Value
Dim Address as String = upsAddress.value
Dim City as String = upsCity.value
Dim State as String = upsState.value
Dim Zipcode as String = upsZipcode.value
'This works'
Dim ups As New UPS(trackNo){
..some code
}
'Im not sure if this will work'
Dim upsAddress as new UPSAddress(Address,City,State,Zipcode){
...some code
}
那麼最後一個不是vb,你在學什麼? – BugFinder
它的vb編譯器,對不起,我沒有提到。 – Cesar
好吧,但最後的代碼不是VB,其C#,如果你不想在C#中做它,那麼你不想在這裏的C#標記..也許這就是爲什麼你在最後一節掙扎,因爲它不是VB – BugFinder