fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. static class Program
  6. {
  7. public static List<T> Splice<T>(this List<T> source, int index, int count)
  8. {
  9. var items = source.GetRange(index, count);
  10. source.RemoveRange(index, count);
  11. return items;
  12. }
  13.  
  14. public static void Main()
  15. {
  16. var data = new List<int> { 1, 2, 3, 4, 5, 6 };
  17. var spliced = data.Splice(2, 1);
  18. Console.WriteLine($@"Old enumerable: { string.Join(", ", data.Select(d => d.ToString()))}");
  19. Console.WriteLine($@"Spliced: { string.Join(", ", spliced.Select(d => d.ToString()))}");
  20. }
  21. }
Success #stdin #stdout 0.01s 131776KB
stdin
Standard input is empty
stdout
Old enumerable: 1, 2, 4, 5, 6
Spliced: 3