我有一个列表,其中有共享ID的integerIds的人,我试图获取每对朋友ID号的产品。因此,朋友ID 2和4将导致8等。
var FriendsWhoShareTheMostTokens = FriendsWithTheirSharedTokensAmount.Select(x => new
{
FriendIdA = x.FriendTo.FriendID,
FriendIdB = x.FriendFor.FriendID,
SharedCountNumber = x.SharedCount
})
.Where(x => x.SharedCountNumber == FriendsWithTheirSharedTokensAmount.Max(y => y.SharedCount))
.ToList();
// need some code here**
foreach (var pairOffriendsWhoSharetheMostTokens in FriendsWhoShareTheMostTokens)
{
}
我可以用Linq完成此操作,还是完成此操作的最佳方法是什么?
最佳答案
编辑
答案很简单
var ProductofGreatestTokenSharers = FriendsWhoShareTheMostTokens.Select(x => new
{
ProductOfIds = x.FriendIdA * x.FriendIdB
}
);