1

あなたはこのクラスを持っています

Private Class MyClass
    Public Property propertyOne() as String
    Public Property propertyTwo() as String
    Public Property propertyN() as Integer
End Class

今、ラムダ式またはlinq式からMyClassのリストを埋めたい....

    Dim myClassList as new List(Of MyClass)
    myClassList = (From lOtherList1 in MyOtherList1.GetAll()
                   join lOtherList2 in MyOterhList2.GetAll() on lOtherList1.Id Equals lOtherList2.Id
                   Select myClassList.Add(new MyClass With { .propertyOne = lOtherList1.Field1, 
                  .propertyTwo = lOtherList1.Field2,
                  .propertyN = lOtherList2.Field1 })).Tolist()

しかし、「式は値を生成しません」というエラーが表示されます。これをどのように作成しますか?

4

2 に答える 2

0

myClassList.Addクエリの間違った部分です。次のように編集してください。

Dim myClassList as new List(Of MyClass)
myClassList = (From lOtherList1 in MyOtherList1.GetAll()
               join lOtherList2 in MyOterhList2.GetAll() 
               on lOtherList1.Id Equals lOtherList2.Id
               Select new MyClass With 
               { 
               .propertyOne = lOtherList1.Field1, 
               .propertyTwo = lOtherList1.Field2,
               .propertyN = lOtherList2.Field1 
               })).Tolist()
于 2012-05-26T16:12:10.033 に答える
0

次のようにします。

myClassList = (From lOtherList1 in MyOtherList1.GetAll()
               Join lOtherList2 in MyOtherList2.GetAll()
               On lOtherList1.Id Equals lOtherList2.Id
               Select new MyClass With
               {
                   .propertyOne = lOtherList1.Field1,
                   .propertyTwo = lOtherList1.Field2,
                   .propertyN = lOtherList2.Field1
               }).ToList()

あなたはほとんど正しいコードを持っていました。への呼び出しを削除する必要がありますmyClassList.Add()

于 2012-05-26T16:12:36.523 に答える