VBです。
今回は、変数を使います。
犬プログラムを改造します。
takk@deb9:~/vbtest$ cat -n test.vb | head
1 Imports System.Console
2
3 Public Class Dog
4 Sub New()
5 WriteLine("犬です")
6 End Sub
7 Sub Bark()
8 WriteLine("ワンワン")
9 End Sub
10 End Class
takk@deb9:~/vbtest$
Barkメソッドで使っているWriteLineの引数を、変数にします。
以下のように修正しました。
takk@deb9:~/vbtest$ cat -n test.vb
1 Imports System.Console
2
3 Public Class Dog
4 Private msg As String = "ワンワン"
5 Sub New()
6 WriteLine("犬です")
7 End Sub
8 Sub Bark()
9 WriteLine(msg)
10 End Sub
11 End Class
12
13 Public Class TestClass
14 <STAThread()> _
15 Shared Sub Main()
16 dim app as new Dog()
17 app.Bark()
18 End Sub
19
20 End Class
takk@deb9:~/vbtest$
当然結果は変化しません。
takk@deb9:~/vbtest$ vbnc test.vb ~省略~ takk@deb9:~/vbtest$ mono test.exe 犬です ワンワン takk@deb9:~/vbtest$
犬っていうのも変数化してみます。
takk@deb9:~/vbtest$ cat -n test.vb | head -12
1 Imports System.Console
2
3 Public Class Dog
4 Private myname As String = "犬"
5 Private msg As String = "ワンワン"
6 Sub New()
7 WriteLine( myname & "です")
8 End Sub
9 Sub Bark()
10 WriteLine(msg)
11 End Sub
12 End Class
takk@deb9:~/vbtest$
わざわざ変数化することにどんな意味があるんでしょうねえ。
takk@deb9:~/vbtest$ vbnc test.vb Visual Basic.Net Compiler version 0.0.0.5943 (Mono 4.0.1 - tarball) Copyright (C) 2004-2010 Rolf Bjarne Kvinge. All rights reserved. Assembly 'test, Version=0.0, Culture=neutral, PublicKeyToken=null' saved successfully to '/home/takk/vbtest/test.exe'. Compilation successful Compilation took 00:00:00.5577930 takk@deb9:~/vbtest$ mono test.exe 犬です ワンワン takk@deb9:~/vbtest$
結果はもちろん変わりません。


コメント