Skip to content

Instantly share code, notes, and snippets.

@bonprosoft
Created June 23, 2012 16:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bonprosoft/2978955 to your computer and use it in GitHub Desktop.
Save bonprosoft/2978955 to your computer and use it in GitHub Desktop.
関数から返されたクラスの中の関数の値って...?(長い
Option Strict On
Module Module1
Sub Main()
'わかりやすくするために、一旦宣言
Dim str As String
'ここを知りたい!
str = GenerateClass("bonpro").GetGreeting
'出力 ->結果: Hello,bonpro
Console.WriteLine(str)
'比較用(2)
'(ILが)わかりやすいように、一旦宣言
Dim item As HelloGenerator
item = New HelloGenerator("VisualBasic")
str = item.GetGreeting
'出力 ->結果: Hello,Visual Basic
Console.WriteLine(str)
'比較用(3)
str = Greeting("VB")
'出力 ->結果: Hello,VB!!
Console.WriteLine(str)
'IL出力結果:
'<<備考>>ルート名前空間はTestになっています(わかりにくい
'<<1番目>>
'IL_0001: ldstr("bonpro")
'IL_0006: call class Test.HelloGenerator Test.Module1::GenerateClass(string)
'IL_000b: callvirt instance string Test.HelloGenerator::GetGreeting()
'IL_0010: stloc(0.1)
'IL_0011: ldloc(0.1)
'IL_0012: call void [mscorlib]System.Console::WriteLine(string)
'<<2番目>>
'IL_0018: ldstr("VisualBasic")
'IL_001d: newobj instance void Test.HelloGenerator::.ctor(string)
'IL_0022: stloc(0.0)
'IL_0023: ldloc(0.0)
'IL_0024: callvirt instance string Test.HelloGenerator::GetGreeting()
'IL_0029: stloc(0.1)
'IL_002a: ldloc(0.1)
'IL_002b: call void [mscorlib]System.Console::WriteLine(string)
'<<3番目>>
'IL_0031: ldstr("VB")
'IL_0036: call string Test.Module1::Greeting(string)
'IL_003b: stloc(0.1)
'IL_003c: ldloc(0.1)
'IL_003d: call void [mscorlib]System.Console::WriteLine(string)
End Sub
Public Function GenerateClass(ByVal Name As String) As HelloGenerator
Return New HelloGenerator(Name)
End Function
Public Function Greeting(ByVal Name As String) As String
Return ("Hello," & Name & "!!")
End Function
End Module
Public Class HelloGenerator
Private _Name As String
Public Sub New(ByVal Name As String)
_Name = Name
End Sub
Public Function GetGreeting() As String
Return ("Hello," & _Name)
End Function
End Class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment