可选的ByRef - VB.NET中有错吗?

时间:2011-01-21 14:51:25

标签: .net vb.net

Public Function Foo(ByRef a As AClass, _
                    Optional ByRef b As BClass = Nothing, _ 
                    Optional ByRef c As CClass = Nothing) As XClass
  

错误:可选参数必须   指定默认值。

是Das吗?

2 个答案:

答案 0 :(得分:3)

这对我来说很好用空类编译。我似乎认为你在其他行或者参数类的定义中有错误。

Public Class Class1

    Public Function Foo(ByRef a As aclass, _
                        Optional ByRef b As bclass = Nothing, _
                        Optional ByRef c As cclass = Nothing) As xclass
        Return Nothing
    End Function

End Class

Public Class aclass    
End Class

Public Class bclass    
End Class

Public Class cclass    
End Class

Public Class xclass
End Class

答案 1 :(得分:1)

如果这是您想要使用的模式,我建议您创建一个不需要这些参数的重载:

Public Function Foo(ByRef a As AClass) As XClass
    Return Foo(a, Nothing, Nothing)
End Function
Public Function Foo(ByRef a As AClass, ByRef b As BClass, ByRef c As CClass) As XClass
    '//Return XClass here
End Function