using System;
using System.Collections.Generic;
public class Program
{
public static void Main()
{
var list1 = new List<string>();
var list2 = new List<double>();
var list3 = new List<MyCustomType>();
var var1 = list1.MakeDefault();
var var2 = list2.MakeDefault();
var var3 = list3.MakeDefault();
Console.WriteLine($"{var1}");
Console.WriteLine($"{var2}");
Console.WriteLine($"{var3}");
}
}
public static class GenericListExtensions
{
public static Tuple<T, Type> MakeDefault<T>(this List<T> list)
{
return Tuple.Create<T, Type>(default(T), typeof(T));
}
}
public class MyCustomType {}
<PropertyGroup>
<RestorePackagesPath>packages</RestorePackagesPath>
</PropertyGroup>
using System;
using System.Linq;
using System.Collections.Generic;
public class Program
{
public static void Main()
{
var list = new List<int> {1,2,3,4,5,6,7,8,9};
list.Top(30).ToList().ForEach(x => Console.WriteLine(x));
}
}
public static class IEnumerableExt
{
public static IEnumerable<T> Top<T>(this IEnumerable<T> list, double percent)
{
var elementCount = (int)Math.Ceiling((double)list.Count() * percent / 100);
return list.OrderByDescending(x => x).Take(elementCount);
}
}