Hi, can someone tell me what is wrong with this?
I am having this error:
Unable to cast object of type
'WhereSelectListIterator`2[Sample.Car,Sample.Car]' to type 'Sample.Cars'.
This is my code, the error occurs in the Red Line:
Partial Public Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim crs As New Cars
crs.Add(New Car() With {.Color = "Rojo"})
crs.Add(New Car() With {.Color = "Verde"})
crs.Add(New Car() With {.Color = "Rojo"})
crs.Add(New Car() With {.Color = "Azul"})
Dim otrocarros As Cars
otrocarros = From c In crs Where c.Color.StartsWith("R") Select c
For Each oc In otrocarros
Response.Write(oc.Color.ToString)
Next
End Sub
End Class
Public Class Cars
Inherits List(Of Car)
End Class
Public Class Car
Private _color As String
Public Property Color() As String
Get
Return _color
End Get
Set(ByVal value As String)
_color = value
End Set
End Property
End Class
Thanks!!!