Try this.
otrocarros = (From c In crs Where c.Color.StartsWith("R") Select c).ToListIt did not work..... got this error: Unable to cast object of type 'System.Collections.Generic.List`1[UseWebParts.Car]' to type 'UseWebParts.Cars'. Juan M. Oviedo From: [email protected] To: [email protected] Subject: [DotNetDevelopment] LINQ Error Date: Wed, 10 Jun 2009 16:56:00 -0500 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!!!
