摘要:(200-06-11) VB.NET 教學
VB 字元宣告
Dim s1 as Char="A"c
*字串是字元的集合物件
Module TestStringObject
'主程式
Public Sub Main()
'定義字串
Dim s1 As String = Nothing
'建構字串(字元一種集合)
'new 建構子() Constructor-同類別名稱 動態記憶體配置Heap堆積
Dim c1() As Char = {"E"c, "r"c, "i"c, "c"c} '陣列初始化
s1 = New String(c1) '建構子
Dim s4 As String = New String(c1)
'字串物件 啟動字串集區
Dim s2 As String = "eric"
Dim s3 As String = "eric"
'Render
System.Console.WriteLine(s1)
System.Console.WriteLine(s4)
'呼叫method 傳遞字串位址
doIt(s1)
'事後
System.Console.WriteLine("事後:" + s1)
End Sub
'程序
's接受s1位址 參考同一個字串物件
Private Sub doIt(ByVal s As String)
System.Console.WriteLine("參數前:" + s) '參考同一個物件
s = "linda" '產生新字串對應.原來還是不動
System.Console.WriteLine("參數後:" + s)
End Sub
End Module
Public Class AppUtil
'共用常數
'public可以看得到 預設為shared(無須物件化) 要用直接載入Global記憶體
'常數隱含shared -形成共用
Public Const COMPANYNAME As String = "巨匠"
'物件的Data Field
Public address As String = "高雄市"
End Class
Module TestConst
'主程式
Public Sub Main()
'使用公司行號
System.Console.WriteLine(AppUtil.COMPANYNAME)
'建構物件
Dim util As AppUtil = New AppUtil() '建構子
util.address = "test"
End Sub
End Module