Question no errors

emadsalib

New member
Joined
Dec 15, 2008
Messages
1
Programming Experience
Beginner
VB.NET:
Public Function GetProduct(ByVal mxID As Integer) As List(Of dtProduct) Implements IService1.GetProduct   
  
        Dim dc As New DataContext()   
        Dim results = From c In dc.dtProducts _   
            Where c.ProductID < mxID _   
             Select new with{c.ProductName,c.ProductPrice}  
  
        Return results.ToList   
    End Function

When i use this code it give a squiggly line under .ToList but if i change the linq to

VB.NET:
Public Function GetProduct(ByVal mxID As Integer) As List(Of dtProduct) Implements IService1.GetProduct   
  
        Dim dc As New DataContext()   
        Dim results = From c In dc.dtProducts _   
            Where c.ProductID < mxID _   
             Select c   
  
        Return results.ToList   
    End Function
no errors

What should I dim the anonymous type as if the output is not a list
 
Last edited by a moderator:
You can't, there are some limitations for anonymous types, these apply for you here:
Caution:

The name of the anonymous type is compiler generated and may vary from compilation to compilation. Your code should not use or rely on the name of an anonymous type because the name might change when a project is recompiled.
an anonymous type cannot be used to define a method signature
See Anonymous Types in help.

Anonymous types can not be declared, only inferred. The squiggliness means what it says, those types are not compatible. Since anonymous types inherits Object type that is the closest you get naming a type if it need be and makes sense.
 
Back
Top