I am new to LINQ, I tried to run the following code and I got InvalidCastException error: "Unable to cast object of type 'd__3a`1[debug.Product]' to type 'debug.Product'" - what is wrong?
Code (VB - using VS2008)
Private Sub btnLinq_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLinq.Click
Dim Products As New List(Of Product)
Dim p1 As New Product
p1._ID = "1"
p1._Name = "Product A"
Products.Add(p1)
Dim p2 As New Product
p2._ID = "2"
p2._Name = "Product B"
Products.Add(p2)
Dim p3 As New Product
p3._ID = "3"
p3._Name = "Product C"
Products.Add(p3)
Dim prod As Product = From p In Products Where p._ID = "1" Select p Take 1
MsgBox(prod._ID)
End Sub
End Class
Public Class Product
Public _ID As String
Public _Name As String
End Class