且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从C#列表中删除重复项和原始项

更新时间:2023-02-13 22:10:06

您可以使用 GroupBy ,然后使用 Where(g => g.Count()== 1)过滤掉所有重复的记录:

You can use GroupBy, followed by Where (g => g.Count() == 1) to filter out all records that have duplicates:

var res = orig.GroupBy(x => x).Where(g => g.Count() == 1).Select(g => g.Key);

为此,您仍然需要覆盖 GetHashCode Equals .

In order for this to work, you still need to override GetHashCode and Equals.