2009-12-16 110 views
1

在兩個不同的網站(在相同的解決方案)相同的代碼,VB.Net(框架3.5)。LINQ選擇:不同的項目相同的代碼不同的結果

驗證碼:

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}) 

一個select返回酒店的大寫字母其他沒有名字。

alt text http://img8.imageshack.us/img8/4509/linqbug1.jpg

我試圖在所有更改屬性的名稱,沒有大寫字母。

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

alt text http://img695.imageshack.us/img695/5231/linqbug2.jpg

感謝。

+0

輸出1和2是相同的... – 2009-12-16 13:03:03

+1

有沒有可能是其他的代碼使用大小寫不同的匿名對象構造? – tvanfosson 2009-12-16 13:03:30

+1

@Fabian - 這是不同的屬性名稱,而不是數據。 – tvanfosson 2009-12-16 13:04:01

回答

1

在您發佈的代碼示例,在匿名對象初始化屬性名稱都寫有一個首字母小寫。你肯定的是,在其他網站上的代碼是真的一樣嗎?我懷疑它使用大寫首字母:

Dim ggg = StaticData.GetLocationsByText(data, CountryId).Select(_ 
Function(o) New With { _ 
.Id = o.UniqueLocation, _ 
.Text = o.DisplayLocation}).ToList() 
+0

這是相同的代碼。 – SirMoreno 2009-12-16 14:48:36

相關問題