프로그래밍/C#

[C#] Linq - GroupBy

Victory_HA 2024. 6. 28. 13:05
            var arr = new item[]
            {
                new item(FeatureType.test1, 0.0),
                new item(FeatureType.test1, 0.0),
                new item(FeatureType.test3, 0.0)
            };

            var list = new List<item>
            {
                new item(FeatureType.test1, 0.0),
                new item(FeatureType.test1, 0.0),
                new item(FeatureType.test3, 0.0)
            };

            var uniqueFeatures = arr
                .GroupBy(x => x.FeatureType)
                .Select(g => new item(g.Key, g.Last().Value))
                .ToList();

 

결과