ソースコード
using System; using System.Collections.Generic; using System.Linq; public static class IEnumerableExt { public static IEnumerable<TKey> GetDuplication<TKey, TSource> ( this IEnumerable<TSource> self, Func<TSource, TKey> keySelector ) { return self .GroupBy( keySelector ) .Where( c => 1 < c.Count() ) .Select( c => c.Key ) ; } }
使用例
var names = list.GetDuplication( c => c.name ); foreach ( var name in names ) { Debug.Log( name ); }