Linq Select Certain Properties Into Another Object?

后端 未结 5 683
情书的邮戳
情书的邮戳 2020-12-09 02:24

So say I have a collection of Bloops

Class Bloop
  Public FirstName
  Public LastName
  Public Address
  Public Number
  Public OtherStuff
End Class
<         


        
5条回答
  •  抹茶落季
    2020-12-09 03:09

    This should do the job:

    Dim results = From item In bloops _
                  Select New Razzie() With _
                  { _
                      .FirstName = item.FirstName, _
                      .LastName = item.LastName _
                  }
    

    And if you want to convert the result from IEnumerable (what the LINQ query returns) to an array or List, just append a call to the ToArray() or ToList() extension methods respectively.

    Edit: Corrected the code so that it now has valid VB.NET 9 syntax.

提交回复
热议问题