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

Question

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))
Was it helpful?

Solution

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)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top