The reason is: the second is not a valid syntax to create an anonymous type.
So this:
new with{y.CompanyName, y.Country}
creates an anonymous type with two properties whereas this
y.countryname, y.countr
does create nothing but a compiler error.
It would make sense if you'd create a class Company
and provide a constructor like:
Public Class Company
Public Sub New(companyName As String, countryName As String)
Me.Country = countryName
Me.Name = companyName
End Sub
Public Country As String
Public Name As String
End Class
Now you can use this syntax to create an IEnumerable(Of Company)
:
Dim companies = customers.
Where(Function(x) x.city = "London").
Select(Function(x) New Company(x.CompanyName, x.Country))
or in query syntax (which i like more in VB):
Dim companies = From c In customers
Where c.City = "London"
Select New Company(c.CompanyName, c.Country)