If your initialization list is simple, like a sequential sequence of values ββfrom from to end , you can simply say
var numbers = Enumerable.Range(from, end - from + 1) .ToList();
If your initialization list is something more complex that can be determined by matching f from int to int , you can say
var numbers = Enumerable.Range(from, end - from + 1) .Select(n => f(n)) .ToList();
For example:
var primes = Enumerable.Range(1, 10) .Select(n => Prime(n)) .ToList();
will generate the first ten primes, assuming Prime is Func<int, int> , which takes int n and returns n th prime.
jason Feb 07 2018-11-11T00: 00Z
source share