ByRef underlined with “Expression Expected” error in VB.Net when trying to pass in a object of type List(Of clsFooDetail)

StackOverflow https://stackoverflow.com/questions/2375846

문제

I work with C# 99% of the time. However, I'm having to update some legacy VB.Net code and encountering an issue with VB.Net code syntax. The error that I get is "ByRef" is underlined and "Expected Expression" tag shows up when you hover over "ByRef".

The "FooDetail.Load" function is written in C# and expects a List object passed as reference. Don't have any trouble using the same function in other C# classes. Can someone indicate what is wrong with below VB.Net code.

Dim FooDetail As New clsFooDetail()
FooDetail.FooID = FooID
Dim lstFooDetail As New List(Of clsFooDetail)
FooDetail.Load(ConnectionString, "Stored Procedure", ByRef lstFooDetail as System.Collection.List(Of(clsFooDetail))
도움이 되었습니까?

해결책

You can't declare a variable in a method call. Nor do you use the equivalent of "out". And don't use "As New" when the method returns a new list. Write it like this:

Dim lstFooDetail As List(Of clsFooDetail)
FooDetail.Load(ConnectionString, "Stored Procedure", lstFooDetail)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top