Answer the question
In order to leave comments, you need to log in
How to return a collection for an IEnumerable extension method?
I have an extension method:
public static ExtensionMethod(this List<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 ?????
}
Answer the question
In order to leave comments, you need to log in
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);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question