Answer the question
In order to leave comments, you need to log in
How to select only duplicate elements from an array?
Given an array:
You need to get an array in which there will be only repeating elements:var a = new[] { 1, 1, 2, 3, 3, 4, 4, 5 };
var a = new[] { 1, 3, 4 };
Answer the question
In order to leave comments, you need to log in
using System;
using System.Collections.Generic;
using System.Linq;
public class Program
{
public static void Main()
{
var a = new[] { 1, 1, 2, 3, 3, 4, 4, 5 };
var r = a.Where(x => a.Count(n => n == x) > 1).Distinct();
foreach (var item in r)
{
Console.WriteLine(item);
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question