[C#] LINQ Group By


In some scenarios, we would like to select each first one row
of the group which we group by personId.

The following code block is a simple example.

var memberList =
    memberSourceData.GroupBy(item => item.personId)
        .Select(chunck => chunck
            .OrderByDescending(c => c.Id)
            .First())
        .ToList();
#C#






你可能感興趣的文章

Day01 命名的原則

Day01 命名的原則

新手必看 - 淺談 檔案格式

新手必看 - 淺談 檔案格式

[筆記] React 隨手記 (React 應用篇.map)

[筆記] React 隨手記 (React 應用篇.map)






留言討論