Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

So say I have a collection of Bloops

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

Then I have a class of Razzies

Class Razzie
  Public FirstName
  Public LastName
End Class

Is it possible using Linq to select the FirstName and LastName out of all the Bloops in the collection of Bloops and return a collection of Razzies? Or am i limited to a For-Loop to do my work?

To clear up any confusion, either VB or C# will do. Also this will probably lead to me asking the question of (What about using a "Where" clause).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
138 views
Welcome To Ask or Share your Answers For Others

1 Answer

List<Bloop> myBloops = new List<Bloops>;
//populate myRazzies
List<Razzie> myRazzies = myBloops.Select(x => new Razzie() { FirstName = x.FirstName, LastName = x.LastName}).ToList();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...