インスタンス メンバおよび 'Me' を構造体のラムダ式内で使用することはできません
更新 : 2007 年 11 月
構造体内から、構造体のインスタンス メンバを参照する、または Me を使用するラムダ式を定義しています。これら 2 つの無効な参照を示すコード例を次に示します。
Structure Structure1
Public InstanceMember As Integer
Public Function ExampleFun() As Integer
'' The error is caused by use of InstanceMember.
'Dim fun1 = Function() InstanceMember
'' The error is caused by use of Me.
'Dim fun2 = Function() Me.InstanceMember
'Return fun1()
End Function
End Structure
Error ID: BC36638
このエラーを解決するには
インスタンス メンバをローカル変数に割り当てて、そのローカル変数をステートメントで使用します。
Public Function ExampleFunFix() As Integer Dim temp = InstanceMember Dim fun1 = Function() temp Return fun1() End Function