Advertisement
Fhernd

PickNthElement.cs

Jul 7th, 2016
764
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.40 KB | None | 0 0
  1. // Pick every 10th element:
  2. int n = 10;
  3.  
  4. // Range of numbers:
  5. List<int> numbers = Enumerable.Range(1,100).ToList();
  6.  
  7. // List of nth elements:
  8. List<int> nthElements = new List<int>();
  9.  
  10. // Pick every 10th element:
  11. Enumerable.Range(0, numbers.Count()/n)
  12.     .ToList()
  13.     .ForEach(k => nthElements.Add(numbers.Skip(k*n).First()));
  14.    
  15. // Outputs the results:
  16. nthElements.Dump("10th elements");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement