「VB.NET」参照型としての文字列型のサンプル
書式
Dim 変数1 As String =値1
Dim 変数2 As String =変数1
使用例
Module Module1
Public Sub Main()
Dim strA As String = "study"
Dim strB As String = strA
Console.WriteLine("インスタンスを参照する")
Console.WriteLine("{0} {1}", strA, strB)
strB = "skill"
Console.WriteLine("新しい文字列型のインスタンス生成")
Console.WriteLine("{0} {1}", strA, strB)
Console.ReadKey()
End Sub
End Module
Module Module1
Public Sub Main()
Dim strA As String = "study"
Dim strB As String = strA
Console.WriteLine("インスタンスを参照する")
Console.WriteLine("{0} {1}", strA, strB)
strB = "skill"
Console.WriteLine("新しい文字列型のインスタンス生成")
Console.WriteLine("{0} {1}", strA, strB)
Console.ReadKey()
End Sub
End Module
Module Module1 Public Sub Main() Dim strA As String = "study" Dim strB As String = strA Console.WriteLine("インスタンスを参照する") Console.WriteLine("{0} {1}", strA, strB) strB = "skill" Console.WriteLine("新しい文字列型のインスタンス生成") Console.WriteLine("{0} {1}", strA, strB) Console.ReadKey() End Sub End Module
実行結果
インスタンスを参照する
study study
新しい文字列型のインスタンス生成
study skill
インスタンスを参照する
study study
新しい文字列型のインスタンス生成
study skill
インスタンスを参照する study study 新しい文字列型のインスタンス生成 study skill