views:

72

answers:

1

The same code on two different web sites (on the same solution), VB.Net (framework 3.5).

The Code:

Public Class UserTest
    Public hhh As Integer
    Public fff As String

    Public Sub New(ByVal hh As Integer, ByVal ff As String)
        Me.hhh = hh
        Me.fff = ff
    End Sub

End Class

        Dim lst As List(Of UserTest) = New List(Of UserTest)
        lst.Add(New UserTest(1, "x"))
        lst.Add(New UserTest(2, "y"))

        Dim myData = lst.Select(Function(o) New With {.id = o.fff, .name = o.hhh})

One select returns property’s names with capital letters the other without.

alt text

I tried changing the properties names and no capital letters at all.

Dim myData = lst.Select(Function(o) New With {.prop1 = o.fff, .prop2 = o.hhh})

alt text

Thanks.

+1  A: 

In the code sample you posted, the property names in the anonymous object initializer are written with a lowercase first letter. Are you sure that the code in the other website is really the same ? I suspect it uses uppercase first letters :

Dim ggg = StaticData.GetLocationsByText(data, CountryId).Select( _
 Function(o) New With { _
 .Id = o.UniqueLocation, _
 .Text = o.DisplayLocation}).ToList()
Thomas Levesque
It's the same code.
SirMoreno