开发者

LINQ Select: different projects same code different results

开发者 https://www.devze.com 2022-12-14 16:38 出处:网络
The same开发者_运维技巧 code on two different web sites (on the same solution), VB.Net (framework 3.5).

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 http://img8.imageshack.us/img8/4509/linqbug1.jpg

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 http://img695.imageshack.us/img695/5231/linqbug2.jpg

Thanks.


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()
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号