public static IEnumerable<int> ExtensionMethod(this IEnumerable<int> list, int percentline)
{
try
{
if (list.Count() <= 100 && list.Count() >= 1)
{
IEnumerable<int> count = list.OrderByDescending(sort => sort).Take((int)(list.Count() * percentline / 100.0f));
Console.WriteLine("Перечень элементов: \n" + string.Join(", ", count));
}
else
{
throw new ArgumentException();
}
}
catch (ArgumentException)
{
Console.Write("ОШИБКА!!!\n");
}
return list;
}
var list = new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
list
.ExtensionMethod(10)
.ExtensionMethod(25);
var lst = new List<int>() { 1, 2, 3, 5, 1, 6, 5 };
var result = lst.Select((el, idx) => (el, idx))
.GroupBy(c => c.el)
.Where(g => g.Count() > 1)
.SelectMany(g => g.Select(c => c.idx).ToList())
.ToList(); // [0, 4, 3, 6]